Example #1
0
    def DELETEgetFullVLANInfo(self, theVLANName=None):

        vlans = []
        vlanNames = self.getVLANNames()
        vlanIDs = self.getVLANGlobalIDs()

        for vlanID in vlanIDs:

            vlanName = vlanNames[vlanID]
            ports = self.__getVLANPorts(vlanID)

            switches = {}
            switches[self.getSwitchID()] = ports

            vlan = VLAN(vlanName, switches, vlanID)
            vlans.append(vlan)

        if (not theVLANName):
            return vlans

        for vlan in vlans:
            if (vlan.getName() == theVLANName):
                return vlan

        return -1
Example #2
0
    def DELETEgetFullVLANInfo(self, theVLANName=None):

        vlans = []
        vlanNames = self.getVLANNames()
        vlanIDs = self.getVLANGlobalIDs()
        
        for vlanID in vlanIDs:

            vlanName = vlanNames[vlanID]
            ports = self.__getVLANPorts(vlanID)

            switches = {}
            switches[self.getSwitchID()] = ports

            vlan = VLAN(vlanName, switches, vlanID)
            vlans.append(vlan)

        if (not theVLANName):
            return vlans

        for vlan in vlans:
            if (vlan.getName() == theVLANName):
                return vlan
            
        return -1
Example #3
0
 def __createNewVlanById(self, vlan_id, switch_obj, switch_str):
     log.info("Creating new id " + str(vlan_id) + " on " + str(switch_str))
     switches = {}
     switches[switch_str] = []
     v = VLAN(None, switches, vlan_id)
     result = switch_obj.createVLAN(v)
     self.__reload_vlan_info(switch_str, switch_obj)
     log.info("result from create vlan id " + str(vlan_id) + " on switch " +
              str(switch_str) + " is " + str(result))
Example #4
0
 def __createNewVlanByName(self, vlan_str, switch_obj, switch_str):
     log.info("Creating new vlan " + str(vlan_str) + " on " +
              str(switch_str))
     switches = {}
     switches[switch_str] = []
     v = VLAN(vlan_str, switches, self.__getNextFreeVlanId(switch_str))
     result = switch_obj.createVLAN(v)
     self.__reload_vlan_info(switch_str, switch_obj)
     log.info("result from create vlan " + str(result))
     return result
Example #5
0
    def getFullVLANInfo(self, theVLANName=None):
        """\brief Returns a list of VLAN objects consisting of all of the vlans in the switch. If the theVLANName parameter is set, the function returns a single VLAN object corresponding to the requested vlan
        \param theVLANName (\c string) The name of the VLAN to retrieve
        \return (\c list of VLAN objects) A list of VLAN objects with the reque\sted information or a VLAN object if a vlan name is specified

        """
        vlans = []

        vlan_names = self.getVLANNames()
        port_ids = self.getPortIDs()

        if theVLANName != None:
            vn = {}
            for v in vlan_names.keys():
                if vlan_names.get(v) == theVLANName:
                    vn[v] = theVLANName
                    vlan_names = vn

        for v in vlan_names:
            if str(v) == "trnet-default":
                pass
            elif str(v) == "token-ring-default":
                pass
            elif str(v) == "fddi-default":
                pass
            elif str(v) == "fddinet-default":
                pass
            else:
                vlans.append(VLAN(vlan_names[v], {}, None, v))

        # get untagged vlan (port based)
        portMapTable = self.snmp.walk(OID.ciscoVmMembershipSummaryMemberPorts)
        for vlan in vlans:
            ports = []
            temp_ports = []
            switches = {}
            # getting port based vlans
            for portMapRow in portMapTable:
                if (portMapRow[0][0][len(portMapRow[0][0]) -
                                     1] == vlan.getInternalID()):
                    ports = self.__parsePortList(portMapRow[0][1], False)
            # getting 802.1Q tagged/untagged vlans

            switches[self.getSwitchName()] = ports
            vlan.setSwitches(switches)

        return vlans
Example #6
0
    def getFullVLANInfo(self, theVLANName=None):
        """\brief Returns a list of VLAN objects consisting of all of the vlan in the switch. If the theVLANName parameter is set, the function returns a single VLAN object corresponding to the requested vlan
        \param theVLANName (\c string) The name of the VLAN to retrieve
        \return (\c list of VLAN objects) A list of VLAN objects with the requested information or a VLAN object if a vlan name is specified
        """
        vlans = []

        vlan_names = self.getVLANNames()
        port_ids = self.getPortIDs()

        # If only wanting information about one vlan, only get that information.
        if theVLANName != None:
            vn = {}

            for v in vlan_names.keys():

                if vlan_names.get(v) == theVLANName:
                    vn[v] = theVLANName
                    vlan_names = vn

        # Create VLAN objects from vlan names
        for v in vlan_names:
            externalID = (self.snmp.get(OID.extremeVlanStaticExternalID +
                                        (v, )))[0][1]
            if self.snmp.getErrorStatus():
                print "unable to get external id of vlan internal ID " + v
                vlans.append(VLAN(vlan_names[v], {}, None, v))
            else:
                vlans.append(VLAN(vlan_names[v], {}, externalID, v))

        for vlan in vlans:
            ifStackStatus = self.snmp.walk(OID.ifStackStatus)
            for ifStackStatusEntry in ifStackStatus:
                if ifStackStatusEntry[0][0][len(ifStackStatusEntry[0][0]) -
                                            2] == vlan.getInternalID():
                    vlan.setTaggedID(
                        ifStackStatusEntry[0][0][len(ifStackStatusEntry[0][0])
                                                 - 1])

            epl = []
            upl = []
            switches = {}
            ports = []
            remove = []
            table2 = table = self.getVLANToInterfacesTable()
            for t in table:
                if t == vlan.getInternalID():
                    for tt in table[t]:
                        for pi in port_ids:
                            if pi[0][1] == rfc1902.Integer32(tt):
                                ports.append(
                                    Port(pi[0][0][len(pi[0][0]) - 1], False,
                                         tt))
                                remove.append(tt)
                    # remove found ports from the list
                    for r in remove:
                        table[t].remove(r)
                    # ports left in table[t] at this point are tagged vlans
                    for vt in table[t]:
                        for ids in table2:
                            if vt == ids:
                                for pi in port_ids:
                                    if pi[0][1] == rfc1902.Integer32(
                                            table2[ids][0]):
                                        ports.append(
                                            Port(pi[0][0][len(pi[0][0]) - 1],
                                                 True, table2[ids][0]))
                                        vlan.setTaggedID(vt)

            switches[self.getSwitchName()] = ports
            vlan.setSwitches(switches)

        return vlans
Example #7
0
    def getFullVLANInfo(self, theVLANName=None):
        """\brief Returns a list of VLAN objects consisting of all of the vlans\ in the switch. If the theVLANName parameter is set, the function returns a sin\gle VLAN object corresponding to the requested vlan
        \param theVLANName (\c string) The name of the VLAN to retrieve
        \return (\c list of VLAN objects) A list of VLAN objects with the reque\sted information or a VLAN object if a vlan name is specified
        """
        vlans = []
        vlan_names = self.getVLANNames()
        port_ids = self.getPortIDs()

        # If only wanting information about one vlan, only get that information.
        if theVLANName != None:
            vn = {}
            for v in vlan_names.keys():
                if vlan_names.get(v) == theVLANName:
                    vn[v] = theVLANName
                    vlan_names = vn

        # Create VLAN objects from vlan names
        for v in vlan_names:
            vlans.append(VLAN(vlan_names[v], {}, v, v))

        portGeneralAccessTable = self.snmp.walk(OID.netgearGeneralPortAccess)
        portVlanTaggedTypeTable = self.snmp.walk(OID.netgearVlanTaggedType)
        for vlan in vlans:
            ports = []
            temp_ports = []
            switches = {}

            for portGeneralAccessTableRow in portGeneralAccessTable:
                #print portGeneralAccessTableRow
                if (portGeneralAccessTableRow[0][1] == rfc1902.Integer32(
                        vlan.getID())):
                    vid = portGeneralAccessTableRow[0][1]
                    pid = portGeneralAccessTableRow[0][0][
                        len(portGeneralAccessTableRow[0][0]) - 1]
                    #print vlan.getID(),vid,pid
                    temp_ports.append(Port(pid, False, pid))
            for portVlanTaggedTypeRow in portVlanTaggedTypeTable:
                vid = portVlanTaggedTypeRow[0][0][
                    len(portVlanTaggedTypeRow[0][0]) - 1]
                pid = portVlanTaggedTypeRow[0][0][
                    len(portVlanTaggedTypeRow[0][0]) - 2]
                vlanType = portVlanTaggedTypeRow[0][1]
                #print portVlanTaggedVlanRow
                if (vid == rfc1902.Integer32(vlan.getID())):
                    if (vlanType == rfc1902.Integer32(1)):
                        temp_ports.append(Port(pid, False, pid))
                    elif (vlanType == rfc1902.Integer32(2)):
                        temp_ports.append(Port(pid, True, pid))
                    else:
                        print "unknown vlan type ", pid, vid, vlanType

                temp_ports.sort()
                # clean list
                if (len(temp_ports) > 0):
                    ports.insert(0, temp_ports[0])
                    temp_ports.remove(ports[0])
                    while (len(temp_ports) > 0):
                        if ports[0] == temp_ports[0]:
                            temp_ports.remove(ports[0])
                        elif (ports[0].getInternalID()
                              == temp_ports[0].getInternalID()
                              and ports[0].getPortNumber()
                              == temp_ports[0].getPortNumber()):
                            if (ports[0].getTagged() == True
                                    and temp_ports[0].getTagged() == False):
                                ports[0].setTagged(False)
                                temp_ports.remove(temp_ports[0])
                        else:
                            ports.insert(0, temp_ports[0])
                            temp_ports.remove(ports[0])
            switches[self.getSwitchName()] = ports
            vlan.setSwitches(switches)
        return vlans
Example #8
0
    def getFullVLANInfo(self, theVLANName=None):
        """\brief Returns a list of VLAN objects consisting of all of the vlans in the switch. If the theVLANName parameter is set, the function returns a single VLAN object corresponding to the requested vlan
        \param theVLANName (\c string) The name of the VLAN to retrieve  
        \return (\c list of VLAN objects) A list of VLAN objects with the requested information or a VLAN object if a vlan name is specified
        """
        vlans = []
        
        untaggedPorts = self.getDot1qVlanStaticUntaggedPorts(True)
        taggedPorts = self.getDot1qVlanStaticEgressPorts(True)
        pvidPorts = self.getDot1qPvid(True)
        vlan_names = self.getVLANNames()
        vlan_ids = self.getDot1qVlanFdbId(True)

        #log.debug( untaggedPorts )
        #log.debug( taggedPorts )
        #log.debug( pvidPorts )

        vlan_list = {} # key -> (name, untagged list, tagged list, pvid list)

        for vid in vlan_names:
            if not vlan_list.has_key(str(vid)):
                vlan_list[str(vid)] = (None,[],[],[])
            vlan_list[str(vid)] = (vlan_names[vid],[],[],[])
            #log.debug("initial vlan list "+str(vlan_list[str(vid)]))

        # put untagged ports into list
        for up in untaggedPorts:
            vid = str(up[0][0][len(up[0][0])-1])
            if not vlan_list.has_key(vid):
                vlan_list[vid] = (None,[],[],[])
                #log.debug("adding new vlan (untagged) "+str(vlan_list[vid]))
            vlan_list[vid] = (vlan_list[vid][0],self.__parsePortList(up[0][1],False), vlan_list[vid][2], vlan_list[vid][3])

        # put tagged ports into list
        for tp in taggedPorts:
            vid = str(tp[0][0][len(tp[0][0])-1])
            if not vlan_list.has_key(vid):
                vlan_list[vid] = (None,[],[],[])
                #log.debug("adding new vlan (tagged) "+str(vlan_list[vid]))
            vlan_list[vid] = (vlan_list[vid][0],vlan_list[vid][1],self.__parsePortList(tp[0][1],True), vlan_list[vid][3])

        # Remove PVID support - Adam 18/02/2008
        # put pvid ports into list
        #for pp in pvidPorts:
        #    vid = str(pp[0][1])
        #    if not vlan_list.has_key(vid):
        #        #log.debug("adding new vlan (vpid) "+str(vlan_list[vid]))
        #        vlan_list[vid] = (None,[],[],[])

        #    temp_port = Port(pp[0][0][len(pp[0][0])-1],
        #                      False,
        #                      pp[0][0][len(pp[0][0])-1])
        #    if (pp[0][0][len(pp[0][0])-1] > self.getNumberofPorts()):
        #        pass
        #    else:
        #        vlan_list[vid][3].append(temp_port)
        #        vlan_list[vid] = (vlan_list[vid][0],
        #                          vlan_list[vid][1],
        #                          vlan_list[vid][2],
        #                          vlan_list[vid][3])
            
        # consider what to do with ports in both tagged and untagged state

        for v in vlan_list:
            switches = {}
            tmp_vlan = VLAN(vlan_list[v][0])
            tmp_vlan.setInternalID(v)
            tmp_vlan.setID(v)
            tmp_vlan.setTaggedID(v)
            switches[self.getSwitchName()] = vlan_list[v][1] + vlan_list[v][2] + vlan_list[v][3] 
            tmp_vlan.setSwitches(switches)
            vlans.append(tmp_vlan)

        for vlan in vlans:
            if (vlan.getName() == theVLANName):
                return [vlan]                    
        return vlans
Example #9
0
#! /usr/bin/env python
from henmanager import HenManager
from auxiliary.hen import Node, SwitchNode, VLAN, Port

manager = HenManager()
manager.initLogging()
nodes = manager.getNodes("switch")

theSwitch = None
for node in nodes.values():
    if (node.getNodeID() == "switch9"):
        theSwitch = node.getInstance()

vlan = VLAN("test", None, "100")
ports = []
port1 = Port("GigabitEthernet2/1/1", False)
port2 = Port("GigabitEthernet2/1/2", True)
ports.append(port1)
ports.append(port2)
vlan.addPorts(ports, "switch7")

#table = theSwitch.getFullMACTable()
#for entry in table:
#    print entry
print theSwitch.createVLAN(vlan)
#print theSwitch.deleteVLAN(vlan.getName())
#print theSwitch.getAvailableTaggedInterfaceInternalID()
#print theSwitch.getNextVLANID()
#print theSwitch.deleteVLAN("cd")
#print theSwitch.addPorts("cd", ports)
#print theSwitch.deletePorts("B", ports)
Example #10
0
    def getFullVLANInfo(self, theVLANName=None):
        """\brief Returns a list of VLAN objects consisting of all of the vlans in the switch. If the theVLANName parameter is set, the function returns a single VLAN object corresponding to the requested vlan
        \param theVLANName (\c string) The name of the VLAN to retrieve  
        \return (\c list of VLAN objects) A list of VLAN objects with the requested information or a VLAN object if a vlan name is specified
        """
        vlans = []

        untaggedPorts = self.getDot1qVlanStaticUntaggedPorts(True)
        taggedPorts = self.getDot1qVlanStaticEgressPorts(True)
        pvidPorts = self.getDot1qPvid(True)
        vlan_names = self.getVLANNames()
        vlan_ids = self.getDot1qVlanFdbId(True)

        #log.debug( untaggedPorts )
        #log.debug( taggedPorts )
        #log.debug( pvidPorts )

        vlan_list = {}  # key -> (name, untagged list, tagged list, pvid list)

        for vid in vlan_names:
            if not vlan_list.has_key(str(vid)):
                vlan_list[str(vid)] = (None, [], [], [])
            vlan_list[str(vid)] = (vlan_names[vid], [], [], [])
            #log.debug("initial vlan list "+str(vlan_list[str(vid)]))

        # put untagged ports into list
        for up in untaggedPorts:
            vid = str(up[0][0][len(up[0][0]) - 1])
            if not vlan_list.has_key(vid):
                vlan_list[vid] = (None, [], [], [])
                #log.debug("adding new vlan (untagged) "+str(vlan_list[vid]))
            vlan_list[vid] = (vlan_list[vid][0],
                              self.__parsePortList(up[0][1], False),
                              vlan_list[vid][2], vlan_list[vid][3])

        # put tagged ports into list
        for tp in taggedPorts:
            vid = str(tp[0][0][len(tp[0][0]) - 1])
            if not vlan_list.has_key(vid):
                vlan_list[vid] = (None, [], [], [])
                #log.debug("adding new vlan (tagged) "+str(vlan_list[vid]))
            vlan_list[vid] = (vlan_list[vid][0], vlan_list[vid][1],
                              self.__parsePortList(tp[0][1],
                                                   True), vlan_list[vid][3])

        # Remove PVID support - Adam 18/02/2008
        # put pvid ports into list
        #for pp in pvidPorts:
        #    vid = str(pp[0][1])
        #    if not vlan_list.has_key(vid):
        #        #log.debug("adding new vlan (vpid) "+str(vlan_list[vid]))
        #        vlan_list[vid] = (None,[],[],[])

        #    temp_port = Port(pp[0][0][len(pp[0][0])-1],
        #                      False,
        #                      pp[0][0][len(pp[0][0])-1])
        #    if (pp[0][0][len(pp[0][0])-1] > self.getNumberofPorts()):
        #        pass
        #    else:
        #        vlan_list[vid][3].append(temp_port)
        #        vlan_list[vid] = (vlan_list[vid][0],
        #                          vlan_list[vid][1],
        #                          vlan_list[vid][2],
        #                          vlan_list[vid][3])

        # consider what to do with ports in both tagged and untagged state

        for v in vlan_list:
            switches = {}
            tmp_vlan = VLAN(vlan_list[v][0])
            tmp_vlan.setInternalID(v)
            tmp_vlan.setID(v)
            tmp_vlan.setTaggedID(v)
            switches[self.getSwitchName(
            )] = vlan_list[v][1] + vlan_list[v][2] + vlan_list[v][3]
            tmp_vlan.setSwitches(switches)
            vlans.append(tmp_vlan)

        for vlan in vlans:
            if (vlan.getName() == theVLANName):
                return [vlan]
        return vlans