Beispiel #1
0
    def __init__(self, config=None):
        Thread.__init__(self)

        # dict from port number to port object
        self.ports = {}

        # dict from port number to list of (timestamp, packet)
        self.packet_queues = {}

        # cvar serves double duty as a regular top level lock and
        # as a condition variable
        self.cvar = Condition()

        # Used to wake up the event loop from another thread
        self.waker = ofutils.EventDescriptor()
        self.killed = False

        self.logger = logging.getLogger("dataplane")
        self.pcap_writer = None

        if config is None:
            self.config = {}
        else:
            self.config = config

        ############################################################
        #
        # The platform/config can provide a custom DataPlanePort class
        # here if you have a custom implementation with different
        # behavior.
        #
        # Set config.dataplane.portclass = MyDataPlanePortClass
        # where MyDataPlanePortClass has the same interface as the class
        # DataPlanePort defined here.
        #
        if "dataplane" in self.config and "portclass" in self.config[
                "dataplane"]:
            self.dppclass = self.config["dataplane"]["portclass"]
        elif have_pypcap:
            self.dppclass = DataPlanePortPcap
        else:
            self.logger.warning(
                "Missing pypcap, VLAN tests may fail. See README for installation instructions."
            )
            self.dppclass = DataPlanePort

        self.start()
Beispiel #2
0
    def __init__(self, config=None):
        Thread.__init__(self)

        # dict from port number to port object
        self.ports = {}

        # dict from port number to list of (timestamp, packet)
        self.packet_queues = {}

        # cvar serves double duty as a regular top level lock and
        # as a condition variable
        self.cvar = Condition()

        # Used to wake up the event loop from another thread
        self.waker = ofutils.EventDescriptor()
        self.killed = False

        self.logger = logging.getLogger("ControlPlane")
        self.pcap_writer = None

        if config is None:
            self.config = {}
        else:
            self.config = config; 

        ############################################################
        #
        # The platform/config can provide a custom DataPlanePort class
        # here if you have a custom implementation with different
        # behavior. 
        #
        # Set config.dataplane.portclass = MyDataPlanePortClass
        # where MyDataPlanePortClass has the same interface as the class
        # DataPlanePort defined here. 
        #
        if "linux" in sys.platform:
            self.dppclass = ControlPlanePortLinux
        else:
            self.dppclass = ControlPlanePortPcap

           
        self.start()
Beispiel #3
0
    def __init__(self,
                 switch=None,
                 host='127.0.0.1',
                 port=6653,
                 max_pkts=1024):
        Thread.__init__(self)
        # Socket related
        self.rcv_size = RCV_SIZE_DEFAULT
        self.listen_socket = None
        self.switch_socket = None
        self.switch_addr = None
        self.connect_cv = Condition()
        self.message_cv = Condition()
        self.tx_lock = Lock()

        # Used to wake up the event loop from another thread
        self.waker = ofutils.EventDescriptor()

        # Counters
        self.socket_errors = 0
        self.parse_errors = 0
        self.packets_total = 0
        self.packets_expired = 0
        self.packets_handled = 0
        self.poll_discards = 0

        # State
        self.sync = Lock()
        self.handlers = {}
        self.keep_alive = False
        self.active = True
        self.initial_hello = True

        # OpenFlow message/packet queue
        # Protected by the packets_cv lock / condition variable
        self.packets = []
        self.packets_cv = Condition()
        self.packet_in_count = 0

        # Settings
        self.max_pkts = max_pkts
        self.switch = switch
        self.passive = not self.switch
        self.host = host
        self.port = port
        self.dbg_state = "init"
        self.logger = logging.getLogger("controller")
        self.filter_packet_in = False  # Drop "excessive" packet ins
        self.pkt_in_run = 0  # Count on run of packet ins
        self.pkt_in_filter_limit = 50  # Count on run of packet ins
        self.pkt_in_dropped = 0  # Total dropped packet ins
        self.transact_to = 15  # Transact timeout default value; add to config

        # Transaction and message type waiting variables
        #   xid_cv: Condition variable (semaphore) for packet waiters
        #   xid: Transaction ID being waited on
        #   xid_response: Transaction response message
        self.xid_cv = Condition()
        self.xid = None
        self.xid_response = None

        self.buffered_input = ""

        # Create listen socket
        if self.passive:
            self.logger.info("Create/listen at " + self.host + ":" +
                             str(self.port))
            ai = socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC,
                                    socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
            # Use first returned addrinfo
            (family, socktype, proto, name, sockaddr) = ai[0]
            self.listen_socket = socket.socket(family, socktype)
            self.listen_socket.setsockopt(socket.SOL_SOCKET,
                                          socket.SO_REUSEADDR, 1)
            self.listen_socket.bind(sockaddr)
            self.listen_socket.listen(LISTEN_QUEUE_SIZE)
Beispiel #4
0
    def __init__(self, config=None):
        Thread.__init__(self)

        # dict from port number to port object
        self.ports = {}

        # dict from port number to list of (timestamp, packet)
        self.packet_queues = {}

        # cvar serves double duty as a regular top level lock and
        # as a condition variable
        self.cvar = Condition()

        # Used to wake up the event loop from another thread
        self.waker = ofutils.EventDescriptor()
        self.killed = False

        self.logger = logging.getLogger("dataplane")
        self.pcap_writer = None

        if config is None:
            self.config = {}
        else:
            self.config = config; 

        ############################################################
        #
        # The platform/config can provide a custom DataPlanePort class
        # here if you have a custom implementation with different
        # behavior. 
        #
        # Set config.dataplane.portclass = MyDataPlanePortClass
        # where MyDataPlanePortClass has the same interface as the class
        # DataPlanePort defined here. 
        #
        if "dataplane" in self.config and "portclass" in self.config["dataplane"]:
            self.dppclass = self.config["dataplane"]["portclass"]
        elif "tstc" in self.config["platform"]:
            self.logger.info( "dataplane use stc adapter")
            self.dppclass = DataPlanePortStc
        elif "test" in self.config["platform"]:
            self.logger.info( "dataplane use stc adapter")
            self.dppclass = DataPlanePortTest
        elif "linux" in sys.platform:
            self.dppclass = DataPlanePortLinux
        else:
            self.dppclass = DataPlanePortPcap

        if "tstc" in self.config["platform"]:
            try: 
                self.stc = stc_proxy.STC(remoteRpcServerIp = self.config["stcSeriverIp"], port = self.config["stcServierPort"])
                self.chassisIp = self.config["chassisIp"]
                self.stc_version = self.stc.get("system1","-Version")  
                self.logger.info("Spirent test center version-%s" % self.stc_version)  
                log_filename_stc = time.strftime("remote_%Y_%m_%d_%H_%M_%S.log",time.localtime(time.time()))
                cResult = self.stc.config("automationoptions -logTo \"" + "log/" + log_filename_stc + "\" -logLevel DEBUG")  
                self.logger.info("enable stc log to file . result %s ." % cResult)

                cResult = self.stc.connect(self.chassisIp)
                self.logger.info("connect to chassis . result %s ." % cResult)
                
                self.project = []
                self.ethPhy = []
                
                prj = self.stc.create("project")
                assert(prj != "")
                self.project.append(prj)
                
            except:
                self.logger.error("Configure remote rpc server failed, Please check whether remote server is running")
                raise
            
        self.start()
Beispiel #5
0
    def __init__(self,
                 switch_socket=None,
                 switch_addr=None,
                 dpid=None,
                 ip='127.0.0.1',
                 max_port=None,
                 max_pkts=1024):
        Thread.__init__(self)
        # feature related
        if max_port == None:
            self.max_port = 2
        else:
            self.max_port = max_port
        self.dpid = dpid
        self.ip = ip
        self.port_desc = None
        self.netconf = None
        # Socket related
        self.rcv_size = RCV_SIZE_DEFAULT
        self.switch_socket = switch_socket
        self.switch_addr = switch_addr
        self.tx_lock = Lock()

        # Used to wake up the event loop from another thread
        self.waker = ofutils.EventDescriptor()

        # Counters
        self.socket_errors = 0
        self.parse_errors = 0
        self.packets_total = 0
        self.packets_expired = 0
        self.packets_handled = 0
        self.poll_discards = 0

        # State
        self.sync = Lock()
        self.handlers = {}
        self.keep_alive = True
        self.active = True
        self.initial_hello = True

        # OpenFlow message/packet queue
        # Protected by the packets_cv lock / condition variable
        self.packets = []
        self.packets_cv = Condition()
        self.packet_in_count = 0

        # Settings
        self.max_pkts = max_pkts
        self.dbg_state = "init"
        self.logger = logging.getLogger("device_agent")

        # Transaction and message type waiting variables
        #   xid_cv: Condition variable (semaphore) for packet waiters
        #   xid: Transaction ID being waited on
        #   xid_response: Transaction response message
        self.xid_cv = Condition()
        self.xid = None
        self.xid_response = None

        self.buffered_input = ""