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($@) { ...@@ -970,17 +970,19 @@ sub getChannelIfIndex($@) {
# vlan_numbers: An array of 802.1Q VLAN numbers to operate on # vlan_numbers: An array of 802.1Q VLAN numbers to operate on
# Returns 1 on success, 0 otherwise # Returns 1 on success, 0 otherwise
# #
# NOTE:NOT-SUPPORTED
#
sub setVlansOnTrunk($$$$) { sub setVlansOnTrunk($$$$) {
my ($self, $modport, $value, @vlan_numbers) = @_; my ($self, $modport, $value, @vlan_numbers) = @_;
my ($RetVal);
my $errors = 0;
my $id = $self->{NAME} . "::setVlansOnTrunk"; my $id = $self->{NAME} . "::setVlansOnTrunk";
warn $id." not supported.\n"; # NOTE: so-called $modport must be a Port instance!
my $swport = $self->convertPortFormat($PORT_FORMAT_SYSDB, $port);
return !$errors; 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($$$$) { ...@@ -994,23 +996,19 @@ sub setVlansOnTrunk($$$$) {
# is the current PVID for this port. # is the current PVID for this port.
# Returns 1 on success, 0 otherwise # Returns 1 on success, 0 otherwise
# #
# NOTE:NOT-SUPPORTED
#
sub enablePortTrunking2($$$$) { sub enablePortTrunking2($$$$) {
my ($self,$port,$native_vlan,$equaltrunking) = @_; my ($self,$port,$native_vlan,$equaltrunking) = @_;
my ($ifIndex) = $self->convertPortFormat($PORT_FORMAT_IFINDEX,$port);
my $id = $self->{NAME} . my $id = $self->{NAME} .
"::enablePortTrunking($port,$native_vlan,$equaltrunking)"; "::enablePortTrunking($port,$native_vlan,$equaltrunking)";
my ($defLists, $rv);
warn $id." not supported.\n"; my $swport = $self->convertPortFormat($PORT_FORMAT_SYSDB, $port);
my $resp = $self->callRPC($id, 'enablePortTrunking',
if ((!$equaltrunking) && (!defined($native_vlan) || ($native_vlan <= 1))) { $swport, $native_vlan, ($equaltrunking?1:0));
warn "$id: inappropriate or missing PVID for trunk\n"; if ($resp) {
return 1;
} else {
return 0; return 0;
} }
return !$rv;
} }
# #
......
...@@ -109,7 +109,7 @@ def _setPortVlan(vlan_num, ports): ...@@ -109,7 +109,7 @@ def _setPortVlan(vlan_num, ports):
pbc = bc.switchIntfConfig.newMember(p) pbc = bc.switchIntfConfig.newMember(p)
except: except:
debug("setPortVlan: Errors when getting port %s, %s" debug("setPortVlan: Errors when getting port %s, %s"
%(str(p), str(sys.exc_info()[0]))) %(str(p), str(sys.exc_info()[1])))
errors += 1 errors += 1
else: else:
pbc.switchportMode = 'access' pbc.switchportMode = 'access'
...@@ -134,7 +134,7 @@ def _removePortsFromVlan(vlan_num, ports): ...@@ -134,7 +134,7 @@ def _removePortsFromVlan(vlan_num, ports):
pbc = bc.switchIntfConfig.newMember(p) pbc = bc.switchIntfConfig.newMember(p)
except: except:
debug("removePortsFromVlan: Errors when getting port %s, %s" debug("removePortsFromVlan: Errors when getting port %s, %s"
%(str(p), str(sys_exc_info()[0]))) %(str(p), str(sys_exc_info()[1])))
errors += 1 errors += 1
else: else:
if pbc.accessVlan == int(vlan_num): if pbc.accessVlan == int(vlan_num):
...@@ -147,11 +147,14 @@ def _removePortsFromVlan(vlan_num, ports): ...@@ -147,11 +147,14 @@ def _removePortsFromVlan(vlan_num, ports):
# Return 1 if exists, 0 otherwise # Return 1 if exists, 0 otherwise
# #
def _vlanTagExist(tag): def _vlanTagExist(tag):
bc = getBridgingConfig(sysdbroot) try:
if bc.vlanConfig.has_key(int(tag)): bc = getBridgingConfig(sysdbroot)
return 1 if bc.vlanConfig.has_key(int(tag)):
else: return 1
return 0 except:
print("_vlanTagExist(", str(tag), ") error: ", str(sys.exc_info()))
return 0
# #
...@@ -160,13 +163,17 @@ def _vlanTagExist(tag): ...@@ -160,13 +163,17 @@ def _vlanTagExist(tag):
# #
def _getVlanName2TagMappings(vnames): def _getVlanName2TagMappings(vnames):
mps = dict() mps = dict()
vc = getBridgingConfig(sysdbroot).vlanConfig try:
vc = getBridgingConfig(sysdbroot).vlanConfig
for vlan in vc.keys():
vid = vc[vlan].configuredName for vlan in vc.keys():
if vid.startswith(VLAN_ID_PREFIX): vid = vc[vlan].configuredName
if len(vnames) == 0 or vid[len(VLAN_ID_PREFIX):] in vnames: if vid.startswith(VLAN_ID_PREFIX):
mps[vid[len(VLAN_ID_PREFIX):]] = vc[vlan].vlanId 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 return mps
...@@ -174,16 +181,19 @@ def _getVlanName2TagMappings(vnames): ...@@ -174,16 +181,19 @@ def _getVlanName2TagMappings(vnames):
# Return 1 if has ports, 0 otherwise. # Return 1 if has ports, 0 otherwise.
# #
def _vlanHasPorts(vlan_num): def _vlanHasPorts(vlan_num):
vs = sysdbroot['bridging']['vlan']['status'].vlanStatus try:
vs = sysdbroot['bridging']['vlan']['status'].vlanStatus
# #
# If there is sub-dir under vlanStatus, then this VLAN has at least on port. # If there is sub-dir under vlanStatus, then this VLAN has at least on port.
# Otherwise this VLAN is empty. # Otherwise this VLAN is empty.
# #
if vs.has_key(int(vlan_num)): if vs.has_key(int(vlan_num)):
return 1 return 1
else: except:
return 0 print("_vlanHasPorts(", str(vlan_num), ") error: ", str(sys.exc_info()))
return 0
# #
# List all experiment VLANs. # List all experiment VLANs.
...@@ -192,23 +202,82 @@ def _vlanHasPorts(vlan_num): ...@@ -192,23 +202,82 @@ def _vlanHasPorts(vlan_num):
# #
def _listVlans(): def _listVlans():
vlans = [] vlans = []
vs = sysdbroot['bridging']['vlan']['status'].vlanStatus try:
vc = getBridgingConfig(sysdbroot).vlanConfig vs = sysdbroot['bridging']['vlan']['status'].vlanStatus
vc = getBridgingConfig(sysdbroot).vlanConfig
vnums = []
for vnum in vc.keys(): vnums = []
if vc[vnum].configuredName.startswith(VLAN_ID_PREFIX): for vnum in vc.keys():
vnums.append(vnum) if vc[vnum].configuredName.startswith(VLAN_ID_PREFIX):
vnums.append(vnum)
for vn in vnums:
ports = []
if vs.has_key(vn):
ports = vs[vn].vlanPortStatus.keys()
vid = vc[vn].configuredName[len(VLAN_ID_PREFIX):]
vlans.append([vid, vn, ports])
except:
print("_listVlans() error: ", str(sys.exc_info()))
return vlans
for vn in vnums: #
ports = [] # Enable port's trunk mode.
if vs.has_key(vn): #
ports = vs[vn].vlanPortStatus.keys() # 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
vid = vc[vn].configuredName[len(VLAN_ID_PREFIX):] #
vlans.append([vid, vn, ports]) # 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
return vlans # 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 # Exported methods list
...@@ -220,7 +289,8 @@ funcs = [(_createVlan, "createVlan"), ...@@ -220,7 +289,8 @@ funcs = [(_createVlan, "createVlan"),
(_vlanTagExist, "vlanTagExist"), (_vlanTagExist, "vlanTagExist"),
(_getVlanName2TagMappings, "getVlanName2TagMappings"), (_getVlanName2TagMappings, "getVlanName2TagMappings"),
(_vlanHasPorts, "vlanHasPorts"), (_vlanHasPorts, "vlanHasPorts"),
(_listVlans, "listVlans") (_listVlans, "listVlans"),
(_enablePortTrunking, "enablePortTrunking")
] ]
s = initRPCServer(BIND_ADDR, RPC_PORT, funcs) 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