Commit 782ae15f authored by Weibin Sun's avatar Weibin Sun Committed by Robert Ricci

Just VLAN number range processing in switch daemin left, all others done.

parent b20bc035
......@@ -920,12 +920,15 @@ sub getStats() {
#
# usage: resetVlanIfOnTrunk(self, modport, vlan)
#
# NOTE:NOT-SUPPORTED
#
sub resetVlanIfOnTrunk($$$) {
my ($self, $modport, $vlan) = @_;
warn $self->{NAME}."::resetVlanIfOnTrunk: unsupported.\n";
#
# MAYBE-TODO: check like snmpit_hp?
#
$self->setVlansOnTrunk($modport, 0, $vlan);
$self->setVlansOnTrunk($modport, 1, $vlan);
return 0;
}
......@@ -949,7 +952,7 @@ sub resetVlanIfOnTrunk($$$) {
# maintenance functions of vlans and so you should check for each port
# any way, and 2.) the check is cheap and can be done in convertPortFormat.
#
# NOTE:NOT-SUPPORTED
# NOTE: NOT-SUPPORTED We mostly use XML-RPC rather than SNMP.
#
sub getChannelIfIndex($@) {
my $self = shift;
......@@ -1017,15 +1020,18 @@ sub enablePortTrunking2($$$$) {
# usage: disablePortTrunking(self, modport)
# Returns 1 on success, 0 otherwise
#
# NOTE:NOT-SUPPORTED
#
sub disablePortTrunking($$) {
my ($self, $port) = @_;
my $id = $self->{NAME} . "::disablePortTrunking($port)";
warn $id." not supported.\n";
return 1;
my $swport = $self->convertPortFormat($PORT_FORMAT_SYSDB, $port);
my $resp = $self->callRPC($id, 'disablePortTrunking',
$swport);
if ($resp) {
return 1;
} else {
return 0;
}
}
......
......@@ -75,21 +75,36 @@ def initRPCServer(bind_addr, port, funcs):
# Return "1" if succeed, error string otherwise
#
def _createVlan(vlan_id, vlan_num):
bc = getBridgingConfig(sysdbroot)
nv = bc.vlanConfig.newMember(int(vlan_num))
nv.configuredName = VLAN_ID_PREFIX + str(vlan_id)
return "1"
try:
bc = getBridgingConfig(sysdbroot)
nv = bc.vlanConfig.newMember(int(vlan_num))
nv.configuredName = VLAN_ID_PREFIX + str(vlan_id)
return 1
except:
print("_createVlan(",
str(vlan_id), ",",
str(vlan_num), ") error: ",
str(sys.exc_info()))
return str(sys.exc_info())
#
# Return 1 on success, error string on failure.
#
def _removeVlan(vlan_num):
bc = getBridgingConfig(sysdbroot)
if vlanExists(sysdbroot, int(vlan_num)):
del bc.vlanConfig[int(vlan_num)]
return 1
else:
return "VLAN #%d not exists."%(int(vlan_num),)
try:
bc = getBridgingConfig(sysdbroot)
if vlanExists(sysdbroot, int(vlan_num)):
del bc.vlanConfig[int(vlan_num)]
return 1
else:
return "VLAN #%d not exists."%(int(vlan_num),)
except:
print("_removeVlan(",
str(vlan_num), ") error: ",
str(sys.exc_info()))
return str(sys.exc_info())
#
# Assign ports to a VLAN, and enable them.
......@@ -97,50 +112,65 @@ def _removeVlan(vlan_num):
# Return #errors.
#
def _setPortVlan(vlan_num, ports):
bc = getBridgingConfig(sysdbroot)
errors = 0
if not vlanExists(sysdbroot, vlan_num):
debug("setPortVlan: VLAN #%d not exists."%(int(vlan_num),))
return 0
for p in ports:
try:
pbc = bc.switchIntfConfig.newMember(p)
except:
debug("setPortVlan: Errors when getting port %s, %s"
%(str(p), str(sys.exc_info()[1])))
errors += 1
else:
pbc.switchportMode = 'access'
pbc.enabled = True
pbc.accessVlan = int(vlan_num)
return errors
#
# Return #errors.
# If ports is empty, remove all ports from the VLAN.
#
def _removePortsFromVlan(vlan_num, ports):
bc = getBridgingConfig(sysdbroot)
errors = 0
try:
bc = getBridgingConfig(sysdbroot)
errors = 0
if not vlanExists(sysdbroot, vlan_num):
debug("setPortVlan: VLAN #%d not exists."%(int(vlan_num),))
return 0
if vlanExists(sysdbroot, int(vlan_num)):
if len(ports) == 0:
ports = bc.switchIntfConfig.keys()
for p in ports:
try:
pbc = bc.switchIntfConfig.newMember(p)
except:
debug("removePortsFromVlan: Errors when getting port %s, %s"
%(str(p), str(sys_exc_info()[1])))
debug("setPortVlan: Errors when getting port %s, %s"
%(str(p), str(sys.exc_info())))
errors += 1
else:
if pbc.accessVlan == int(vlan_num):
pbc.accessVlan = DEFAULT_VLAN_NUM
pbc.switchportMode = 'access'
pbc.enabled = True
pbc.accessVlan = int(vlan_num)
return errors
except:
print("_setPortVlan(",
str(vlan_num), ",",
str(ports), ") error: ",
str(sys.exc_info()))
return 1
return errors
#
# Return #errors.
# If ports is empty, remove all ports from the VLAN.
#
def _removePortsFromVlan(vlan_num, ports):
try:
bc = getBridgingConfig(sysdbroot)
errors = 0
if vlanExists(sysdbroot, int(vlan_num)):
if len(ports) == 0:
ports = bc.switchIntfConfig.keys()
for p in ports:
try:
pbc = bc.switchIntfConfig.newMember(p)
except:
debug("removePortsFromVlan: Errors when getting port %s, %s"
%(str(p), str(sys_exc_info())))
errors += 1
else:
if pbc.accessVlan == int(vlan_num):
pbc.accessVlan = DEFAULT_VLAN_NUM
return errors
except:
print("_removePortsFromVlan(",
str(vlan_num), ",",
str(ports), ") error: ",
str(sys.exc_info()))
return 1
#
......@@ -249,6 +279,18 @@ def _enablePortTrunking(port, native_vlan_num, tag_native):
else:
return 1
#
# Disable port's trunk mode
#
def _disablePortTrunking(port):
try:
pass
except:
return 0
else:
return 1
#
# Set allowed VLANs on trunked port.
#
......@@ -290,7 +332,9 @@ funcs = [(_createVlan, "createVlan"),
(_getVlanName2TagMappings, "getVlanName2TagMappings"),
(_vlanHasPorts, "vlanHasPorts"),
(_listVlans, "listVlans"),
(_enablePortTrunking, "enablePortTrunking")
(_enablePortTrunking, "enablePortTrunking"),
(_disablePortTrunking, "disablePortTrunking"),
(_setAllowedVlansOnTrunkedPort, "setAllowedVlansOnTrunkedPort")
]
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