Example #1
0
    def __init__(self):
        Daemon.__init__(self)
        # Initalise variables
        self.__henManager = HenManager()
        self.__nodes = None
        self.__vlans = {}  #
        self.__vlan_info = {}  # switch_name -> [vlan_name,vlan_name,...]
        self.__switch_instances = {}
        self.__test_mode = False
        self.__minimum_id = 200
        self.__maximum_id = 2000
        self.__vlanOwnerFilename = "/usr/local/hen/etc/switchd/vlan_owner.dat"

        self.__int_to_vlan = {}  # (computer_str,interface_str) -> vlan_name

        self.__switchdb = SwitchDB()
        log.debug("Switchdb " + str(self.__switchdb))
        # Register hen rpc methods and handlers
        log.debug("Registering methods")
        self.__registerMethods()
        # Load vlan info
        log.debug("Loading vlan info")
        self.__initaliseVlanInfo()
        # Setup mac polling
        log.debug("Loading henmanager")
        self.__switchdb.setHenManager(self.__henManager)
        log.debug("Loading links Db")
        self.__switchdb.loadLinksDb()
        log.debug("Initiating Nodes")
        self.initiateNodes()

        # vlan owners
        self.__vlan_owner_name = {}
        self.__vlan_name_owner = {}
        self.loadVlanOwnerFile()
Example #2
0
 def __init__(self):
     Daemon.__init__(self)
     # Initalise variables
     self.__henManager = HenManager()
     self.__nodes = None
     self.__vlans = {} # 
     self.__vlan_info = {} # switch_name -> [vlan_name,vlan_name,...]
     self.__switch_instances = {}
     self.__test_mode = False
     self.__minimum_id = 200
     self.__maximum_id = 2000
     self.__vlanOwnerFilename = "/usr/local/hen/etc/switchd/vlan_owner.dat"
     
     self.__int_to_vlan = {} # (computer_str,interface_str) -> vlan_name
     
     self.__switchdb = SwitchDB()
     log.debug("Switchdb "+str(self.__switchdb))
     # Register hen rpc methods and handlers
     log.debug("Registering methods")
     self.__registerMethods()
     # Load vlan info
     log.debug("Loading vlan info")
     self.__initaliseVlanInfo()
     # Setup mac polling
     log.debug("Loading henmanager")
     self.__switchdb.setHenManager(self.__henManager)
     log.debug("Loading links Db")
     self.__switchdb.loadLinksDb()
     log.debug("Initiating Nodes")
     self.initiateNodes()
     
     # vlan owners
     self.__vlan_owner_name = {}
     self.__vlan_name_owner = {}
     self.loadVlanOwnerFile()
Example #3
0
class SwitchControl(Daemon):
    """\brief Implements basic switch daemon functionality.
    """
    __version = "Switch Daemon v0.2 (simple)"
    __henManager = None
    __update_timer = None
    __update_lock = threading.Lock()
    
    __accept_connections = True
    __switchdb = None
    __nodeInstances = None
                                        
    def __init__(self):
        Daemon.__init__(self)
        # Initalise variables
        self.__henManager = HenManager()
        self.__nodes = None
        self.__vlans = {} # 
        self.__vlan_info = {} # switch_name -> [vlan_name,vlan_name,...]
        self.__switch_instances = {}
        self.__test_mode = False
        self.__minimum_id = 200
        self.__maximum_id = 2000
        self.__vlanOwnerFilename = "/usr/local/hen/etc/switchd/vlan_owner.dat"
        
        self.__int_to_vlan = {} # (computer_str,interface_str) -> vlan_name
        
        self.__switchdb = SwitchDB()
        log.debug("Switchdb "+str(self.__switchdb))
        # Register hen rpc methods and handlers
        log.debug("Registering methods")
        self.__registerMethods()
        # Load vlan info
        log.debug("Loading vlan info")
        self.__initaliseVlanInfo()
        # Setup mac polling
        log.debug("Loading henmanager")
        self.__switchdb.setHenManager(self.__henManager)
        log.debug("Loading links Db")
        self.__switchdb.loadLinksDb()
        log.debug("Initiating Nodes")
        self.initiateNodes()
        
        # vlan owners
        self.__vlan_owner_name = {}
        self.__vlan_name_owner = {}
        self.loadVlanOwnerFile()
        
            
    def __registerMethods(self):
        # hm commands
        self.registerMethodHandler("get_port_vlans_for_name", self.getPortVlansForName)
        self.registerMethodHandler("get_switch_port_vlans_for_name", self.getSwitchPortVlansForName)
        self.registerMethodHandler("get_vlan_for_name", self.getVlanForName)
        self.registerMethodHandler("get_vlan_for_user", self.getVlanForUser)
        self.registerMethodHandler("create_vlan_for_user", self.createVlanForUser)
        # older stuff

        self.registerMethodHandler("create_vlan_by_name", self.createVlanByName)
        self.registerMethodHandler("delete_vlan_by_name", self.deleteVlanByName)
        self.registerMethodHandler("add_port_to_vlan_by_name", self.addPortToVlanByName)
        self.registerMethodHandler("delete_port_from_vlan", self.deletePortFromVlan)
        self.registerMethodHandler("list_ports_on_vlan_on_switch", self.listPortsOnVlanOnSwitch)
        self.registerMethodHandler("list_vlans_on_switch", self.listVlansOnSwitch)
        self.registerMethodHandler("get_vlan_id_for_port", self.getVlanIdForPort)
        self.registerMethodHandler("get_vlan_name_for_port", self.getVlanNameForPort)
        # Testing code, might go away at any time
        #self.registerMethodHandler("get_next_free_vlan_id", self.getNextFreeVlanId)
        self.registerMethodHandler("add_port_to_vlan_by_id", self.addPortToVlanById)
        self.registerMethodHandler("enable_test_mode",self.enableTestMode)
        self.registerMethodHandler("disable_test_mode",self.disableTestMode)
        self.registerMethodHandler("clear_vlans", self.clearVlans)
        self.registerMethodHandler("list_empty_vlans_on_switch",self.listEmptyVlansOnSwitch)
        self.registerMethodHandler("clear_empty_vlans_on_switch",self.clearEmptyVlansOnSwitch)

    # HM COMMANDS  ########################################

    def createVlanForUser(self,prot,seq,ln,payload):
        args = pickle.loads(payload)
        if len(args) != 2:
            code = 400
            reply = str("Incorrect number of arguments")
            self.__sendReply(prot,code,seq,reply)
            return
        vlan_str = args[0]
        user_str = args[1]
        try:
            for vlan_owner in self.__vlan_owner_name:
                print vlan_owner
            
            code = 200
            v = VlanOwner(vlan_str,user_str)
            self.__vlan_owners.append(v)
            reply = str("Trying to create ")+str(v)
            self.__sendReply(prot,code,seq,reply)
            return
                                            
        except Exception, e:
            code = 400
            reply = "Error with createVlanForUser "+str(e)
            self.__sendReply(prot,code,seq,reply)
            return
Example #4
0
class SwitchControl(Daemon):
    """\brief Implements basic switch daemon functionality.
    """
    __version = "Switch Daemon v0.2 (simple)"
    __henManager = None
    __update_timer = None
    __update_lock = threading.Lock()

    __accept_connections = True
    __switchdb = None
    __nodeInstances = None

    def __init__(self):
        Daemon.__init__(self)
        # Initalise variables
        self.__henManager = HenManager()
        self.__nodes = None
        self.__vlans = {}  #
        self.__vlan_info = {}  # switch_name -> [vlan_name,vlan_name,...]
        self.__switch_instances = {}
        self.__test_mode = False
        self.__minimum_id = 200
        self.__maximum_id = 2000
        self.__vlanOwnerFilename = "/usr/local/hen/etc/switchd/vlan_owner.dat"

        self.__int_to_vlan = {}  # (computer_str,interface_str) -> vlan_name

        self.__switchdb = SwitchDB()
        log.debug("Switchdb " + str(self.__switchdb))
        # Register hen rpc methods and handlers
        log.debug("Registering methods")
        self.__registerMethods()
        # Load vlan info
        log.debug("Loading vlan info")
        self.__initaliseVlanInfo()
        # Setup mac polling
        log.debug("Loading henmanager")
        self.__switchdb.setHenManager(self.__henManager)
        log.debug("Loading links Db")
        self.__switchdb.loadLinksDb()
        log.debug("Initiating Nodes")
        self.initiateNodes()

        # vlan owners
        self.__vlan_owner_name = {}
        self.__vlan_name_owner = {}
        self.loadVlanOwnerFile()

    def __registerMethods(self):
        # hm commands
        self.registerMethodHandler("get_port_vlans_for_name",
                                   self.getPortVlansForName)
        self.registerMethodHandler("get_switch_port_vlans_for_name",
                                   self.getSwitchPortVlansForName)
        self.registerMethodHandler("get_vlan_for_name", self.getVlanForName)
        self.registerMethodHandler("get_vlan_for_user", self.getVlanForUser)
        self.registerMethodHandler("create_vlan_for_user",
                                   self.createVlanForUser)
        # older stuff

        self.registerMethodHandler("create_vlan_by_name",
                                   self.createVlanByName)
        self.registerMethodHandler("delete_vlan_by_name",
                                   self.deleteVlanByName)
        self.registerMethodHandler("add_port_to_vlan_by_name",
                                   self.addPortToVlanByName)
        self.registerMethodHandler("delete_port_from_vlan",
                                   self.deletePortFromVlan)
        self.registerMethodHandler("list_ports_on_vlan_on_switch",
                                   self.listPortsOnVlanOnSwitch)
        self.registerMethodHandler("list_vlans_on_switch",
                                   self.listVlansOnSwitch)
        self.registerMethodHandler("get_vlan_id_for_port",
                                   self.getVlanIdForPort)
        self.registerMethodHandler("get_vlan_name_for_port",
                                   self.getVlanNameForPort)
        # Testing code, might go away at any time
        #self.registerMethodHandler("get_next_free_vlan_id", self.getNextFreeVlanId)
        self.registerMethodHandler("add_port_to_vlan_by_id",
                                   self.addPortToVlanById)
        self.registerMethodHandler("enable_test_mode", self.enableTestMode)
        self.registerMethodHandler("disable_test_mode", self.disableTestMode)
        self.registerMethodHandler("clear_vlans", self.clearVlans)
        self.registerMethodHandler("list_empty_vlans_on_switch",
                                   self.listEmptyVlansOnSwitch)
        self.registerMethodHandler("clear_empty_vlans_on_switch",
                                   self.clearEmptyVlansOnSwitch)

    # HM COMMANDS  ########################################

    def createVlanForUser(self, prot, seq, ln, payload):
        args = pickle.loads(payload)
        if len(args) != 2:
            code = 400
            reply = str("Incorrect number of arguments")
            self.__sendReply(prot, code, seq, reply)
            return
        vlan_str = args[0]
        user_str = args[1]
        try:
            for vlan_owner in self.__vlan_owner_name:
                print vlan_owner

            code = 200
            v = VlanOwner(vlan_str, user_str)
            self.__vlan_owners.append(v)
            reply = str("Trying to create ") + str(v)
            self.__sendReply(prot, code, seq, reply)
            return

        except Exception, e:
            code = 400
            reply = "Error with createVlanForUser " + str(e)
            self.__sendReply(prot, code, seq, reply)
            return