Commit b20bc035 authored by Weibin Sun's avatar Weibin Sun Committed by Robert Ricci

half way done trunking

parent 78446f03
......@@ -970,17 +970,19 @@ sub getChannelIfIndex($@) {
# vlan_numbers: An array of 802.1Q VLAN numbers to operate on
# Returns 1 on success, 0 otherwise
#
# NOTE:NOT-SUPPORTED
#
sub setVlansOnTrunk($$$$) {
my ($self, $modport, $value, @vlan_numbers) = @_;
my ($RetVal);
my $errors = 0;
my $id = $self->{NAME} . "::setVlansOnTrunk";
warn $id." not supported.\n";
return !$errors;
# NOTE: so-called $modport must be a Port instance!
my $swport = $self->convertPortFormat($PORT_FORMAT_SYSDB, $port);
my $resp = $self->callRPC($id, 'setAllowedVlansOnTrunkedPort', $swport,
($value?1:0), \@vlan_numbers);
if ($resp) {
return 1;
} else {
return 0;
}
}
#
......@@ -994,23 +996,19 @@ sub setVlansOnTrunk($$$$) {
# is the current PVID for this port.
# Returns 1 on success, 0 otherwise
#
# NOTE:NOT-SUPPORTED
#
sub enablePortTrunking2($$$$) {
my ($self,$port,$native_vlan,$equaltrunking) = @_;
my ($ifIndex) = $self->convertPortFormat($PORT_FORMAT_IFINDEX,$port);
my $id = $self->{NAME} .
"::enablePortTrunking($port,$native_vlan,$equaltrunking)";
my ($defLists, $rv);
warn $id." not supported.\n";
if ((!$equaltrunking) && (!defined($native_vlan) || ($native_vlan <= 1))) {
warn "$id: inappropriate or missing PVID for trunk\n";
my $swport = $self->convertPortFormat($PORT_FORMAT_SYSDB, $port);
my $resp = $self->callRPC($id, 'enablePortTrunking',
$swport, $native_vlan, ($equaltrunking?1:0));
if ($resp) {
return 1;
} else {
return 0;
}
return !$rv;
}
#
......
......@@ -109,7 +109,7 @@ def _setPortVlan(vlan_num, ports):
pbc = bc.switchIntfConfig.newMember(p)
except:
debug("setPortVlan: Errors when getting port %s, %s"
%(str(p), str(sys.exc_info()[0])))
%(str(p), str(sys.exc_info()[1])))
errors += 1
else:
pbc.switchportMode = 'access'
......@@ -134,7 +134,7 @@ def _removePortsFromVlan(vlan_num, ports):
pbc = bc.switchIntfConfig.newMember(p)
except:
debug("removePortsFromVlan: Errors when getting port %s, %s"
%(str(p), str(sys_exc_info()[0])))
%(str(p), str(sys_exc_info()[1])))
errors += 1
else:
if pbc.accessVlan == int(vlan_num):
......@@ -147,10 +147,13 @@ def _removePortsFromVlan(vlan_num, ports):
# Return 1 if exists, 0 otherwise
#
def _vlanTagExist(tag):
try:
bc = getBridgingConfig(sysdbroot)
if bc.vlanConfig.has_key(int(tag)):
return 1
else:
except:
print("_vlanTagExist(", str(tag), ") error: ", str(sys.exc_info()))
return 0
......@@ -160,6 +163,7 @@ def _vlanTagExist(tag):
#
def _getVlanName2TagMappings(vnames):
mps = dict()
try:
vc = getBridgingConfig(sysdbroot).vlanConfig
for vlan in vc.keys():
......@@ -167,6 +171,9 @@ def _getVlanName2TagMappings(vnames):
if vid.startswith(VLAN_ID_PREFIX):
if len(vnames) == 0 or vid[len(VLAN_ID_PREFIX):] in vnames:
mps[vid[len(VLAN_ID_PREFIX):]] = vc[vlan].vlanId
except:
print("_getVlanName2TagMappings(",
str(vnames), ") error: ", str(sys.exc_info()))
return mps
......@@ -174,6 +181,7 @@ def _getVlanName2TagMappings(vnames):
# Return 1 if has ports, 0 otherwise.
#
def _vlanHasPorts(vlan_num):
try:
vs = sysdbroot['bridging']['vlan']['status'].vlanStatus
#
......@@ -182,7 +190,9 @@ def _vlanHasPorts(vlan_num):
#
if vs.has_key(int(vlan_num)):
return 1
else:
except:
print("_vlanHasPorts(", str(vlan_num), ") error: ", str(sys.exc_info()))
return 0
#
......@@ -192,6 +202,7 @@ def _vlanHasPorts(vlan_num):
#
def _listVlans():
vlans = []
try:
vs = sysdbroot['bridging']['vlan']['status'].vlanStatus
vc = getBridgingConfig(sysdbroot).vlanConfig
......@@ -207,9 +218,67 @@ def _listVlans():
vid = vc[vn].configuredName[len(VLAN_ID_PREFIX):]
vlans.append([vid, vn, ports])
except:
print("_listVlans() error: ", str(sys.exc_info()))
return vlans
#
# Enable port's trunk mode.
#
# Note: First clear all existing allowed VLANs, then
# set port mode, and set nativeVlan or allowedVlans.
#
# TODO: Is there any other thing as third?
#
def _enablePortTrunking(port, native_vlan_num, tag_native):
try:
pc = getBridgingConfig(sysdbroot).switchIntfConfig.newMember(str(port))
pc.switchportMode = 'trunk'
if int(tag_native) == 1:
pc.trunkNativeVlan = 0
else:
pc.trunkNativeVlan = int(native_vlan_num)
pc.trunkAllowedVlans = str(native_vlan_num)
pc.enabled = True
except:
print("_enablePortTrunking(", str(port), ",", str(native_vlan_num),
",", str(tag_native), ") error: ", str(sys.exc_info()))
return 0
else:
return 1
#
# Set allowed VLANs on trunked port.
#
# usage:
#
def _setAllowedVlansOnTrunkedPort(port, allow, vnums):
try:
pc = getBridgingConfig(sysdbroot).switchIntfConfig.newMember(str(port))
if pc.switchportMode == 'access':
native_vlan = pc.accessVlan
pc.switchportMode = 'trunk'
if native_vlan != 1:
pc.trunkNativeVlan = native_vlan
pc.trunkAllowedVlans = str(native_vlan)
else:
pc.trunkNativeVlan = 0
pc.trunkAllowedVlans = ''
else:
pass
# TODO: fix VLAN range
if int(allow) == 1:
if pc.trunkAllowedVlans != "":
pc.trunkAllowedVlans += "," + ",".join(map(str, vnums))
else:
pc.trunkAllowedVlans = ",".join(map(str, vnums))
else:
pc.trunkAllowedVlans = exceptVlans(pc.trunkAllowedVlans, map(int, vnums))
#
# Exported methods list
#
......@@ -220,7 +289,8 @@ funcs = [(_createVlan, "createVlan"),
(_vlanTagExist, "vlanTagExist"),
(_getVlanName2TagMappings, "getVlanName2TagMappings"),
(_vlanHasPorts, "vlanHasPorts"),
(_listVlans, "listVlans")
(_listVlans, "listVlans"),
(_enablePortTrunking, "enablePortTrunking")
]
s = initRPCServer(BIND_ADDR, RPC_PORT, funcs)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment