def __init__(self, sock): self._previous_stats = [] self.ofnexus = _dummyOFNexus self.sock = sock self.buf = b'' Connection.ID += 1 self.ID = Connection.ID # DPID of connected switch. None before connection is complete. self.dpid = None # Switch features reply. Set during handshake. self.features = None # Switch desc stats reply. Set during handshake ordinarily, but may # be None. self.description = None self.disconnected = False self.disconnection_raised = False self.connect_time = None self.idle_time = time.time() self.send(of.ofp_hello()) self.original_ports = PortCollection() self.ports = PortCollection() self.ports._chain = self.original_ports #TODO: set a time that makes sure we actually establish a connection by # some timeout self.unpackers = unpackers self.handlers = HandshakeOpenFlowHandlers().handlers
def __init__(self, sock, send_hello=True): self._previous_stats = [] self.ofnexus = _dummyOFNexus self.sock = sock self.buf = '' Connection.ID += 1 self.ID = Connection.ID # TODO: dpid and features don't belong here; they should be eventually # be in topology.switch self.dpid = None self.features = None self.disconnected = False self.disconnection_raised = False self.connect_time = None self.idle_time = time.time() if send_hello: log.debug('sending of.ofp_hello') self.send(of.ofp_hello()) else: log.debug('sending of.ofp_features_request') msg = of.ofp_features_request() log.debug(msg) self.send(msg) self.original_ports = PortCollection() self.ports = PortCollection() self.ports._chain = self.original_ports
def __init__ (self, sock): self._previous_stats = [] self.ofnexus = _dummyOFNexus self.sock = sock self.buf = b'' Connection.ID += 1 self.ID = Connection.ID # DPID of connected switch. None before connection is complete. self.dpid = None # Switch features reply. Set during handshake. self.features = None # Switch desc stats reply. Set during handshake ordinarily, but may # be None. self.description = None self.disconnected = False self.disconnection_raised = False self.connect_time = None self.idle_time = time.time() self.send(of.ofp_hello()) self.original_ports = PortCollection() self.ports = PortCollection() self.ports._chain = self.original_ports #TODO: set a time that makes sure we actually establish a connection by # some timeout self.unpackers = unpackers self.handlers = HandshakeOpenFlowHandlers().handlers
def __init__(self, sock): self._previous_stats = [] self.ofnexus = _dummyOFNexus self.sock = sock self.buf = '' Connection.ID += 1 self.ID = Connection.ID # TODO: dpid and features don't belong here; they should be eventually # be in topology.switch self.dpid = None self.features = None self.disconnected = False self.disconnection_raised = False self.connect_time = None self.idle_time = time.time() self.send(of.ofp_hello()) self.original_ports = PortCollection() self.ports = PortCollection() self.ports._chain = self.original_ports #TODO: set a time that makes sure we actually establish a connection by # some timeout """
def open(self): self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._sock.connect((self._host, self._port)) self.start() # When we have a new controller, send it a 'hello' (acting like # we are a switch to whom they are talking hello_msg = of.ofp_hello() self.send(hello_msg)
def __init__(self, sock): self._previous_stats = [] self.sock = sock self.buf = '' Connection.ID += 1 self.ID = Connection.ID self.dpid = None self.features = None self.disconnected = False self.send(of.ofp_hello())
def __init__ (self, sock): self._previous_stats = [] self.sock = sock self.buf = '' Connection.ID += 1; self.ID = Connection.ID self.dpid = None self.features = None self.disconnected = False self.send(of.ofp_hello())
def __init__(self, sock): self._previous_stats = [] self.ofnexus = _dummyOFNexus self.sock = sock self.buf = '' Connection.ID += 1 self.ID = Connection.ID # TODO: dpid and features don't belong here; they should be eventually # be in topology.switch self.dpid = None self.features = None self.disconnected = False self.connect_time = None self.send(of.ofp_hello())
def __init__ (self, sock): self._previous_stats = [] self.ofnexus = _dummyOFNexus self.sock = sock self.buf = '' Connection.ID += 1 self.ID = Connection.ID # TODO: dpid and features don't belong here; they should be eventually # be in topology.switch self.dpid = None self.features = None self.disconnected = False self.connect_time = None self.send(of.ofp_hello())
def check_socket(self): pkt_count = 0 while True: pkt_count += 1 buff = self.s.recv(100) pkt = of.ofp_header() pkt.unpack(buff) #print('[{}][check_socket]recved: ', len(buff)) print('\n[{0}] received [{1}]byte data.'.format(pkt_count, len(buff))) print(pkt.show()) if pkt.header_type == gini_of.OFPT_HELLO: # OFPT_HELLO print("OFPT_HELLO msg: ") pkt = of.ofp_hello() pkt.unpack(buff) self.process_hello(pkt) elif pkt.header_type == gini_of.OFPT_ECHO_REQUEST: print("OFPT_ECHO_REPLY msg: ") pkt = of.ofp_echo_request() pkt.unpack(buff) self.process_echo_request(pkt) elif pkt.header_type == gini_of.OFPT_FEATURES_REQUEST: print("OFPT_FEATURES_REQUEST msg: ") pkt = of.ofp_features_request() pkt.unpack(buff) self.process_features_request(pkt) elif pkt.header_type == gini_of.OFPT_SET_CONFIG: print("OFPT_SET_CONFIG msg: ") pkt = of.ofp_set_config() pkt.unpack(buff) self.process_set_config(pkt) elif pkt.header_type == gini_of.OFPT_FLOW_MOD: print("OFPT_FLOW_MOD msg: ") pkt = giniclass_flow_mod() pkt.unpack(buff) self.process_flow_mod(pkt) elif pkt.header_type == gini_of.OFPT_BARRIER_REQUEST: print("OFPT_BARRIER_REQUEST msg: ") pkt = of.ofp_barrier_request() pkt.unpack(buff) self.process_barrier_request(pkt) else: print("Unknown type!: ", pkt.header_type, "details: ") print(pkt.show())
def analysis_data(self, data): log.debug("controller -->switch: %s" % binascii.hexlify(data)) self.version = ord(data[0]) self.header_type = ord(data[1]) self.of_len = ord(data[2]) * 256 + ord(data[3]) self.of_load = data[4:] if self.version != 1: log.debug("The openflow protocol is not supported, it is %d" % of_ver) if self.header_type == 0: # this is the hello message log.debug("controller -->switch hello message") self.xid = ord(data[6]) * 256 + ord(data[7]) hello_reply = of.ofp_hello() log.debug("switch --> controller: %s" % binascii.hexlify(hello_reply.pack())) self.socket.send(hello_reply.pack()) elif self.header_type == 5: # this is the feature request message log.debug("controller --> switch feature request package") feature_reply = of.ofp_features_reply() log.debug("switch --> controller: %s" % binascii.hexlify(feature_reply.pack())) self.socket.send(feature_reply.pack()) elif self.header_type == 9: # the set config package log.debug("controller --> switch set config package") elif self.header_type == 14: # barrier request log.debug("controller --> switch barrier request package") # the xid must the same as barrier request barrier_reply = of.ofp_barrier_reply() barrier_reply.xid = ord(data[-1]) log.debug("switch --> controller: %s" % binascii.hexlify(barrier_reply.pack())) self.socket.send(barrier_reply.pack()) else: log.debug("controller --> switch unknow package") self.telnet.write( "%s" % binascii.hexlify(data)) # write testin data to cli log.debug("controller --> switch: %s" % binascii.hexlify(data))
def __init__ (self, sock): self._previous_stats = [] self.ofnexus = _dummyOFNexus self.sock = sock self.buf = '' Connection.ID += 1 self.ID = Connection.ID # TODO: dpid and features don't belong here; they should be eventually # be in topology.switch self.dpid = None self.features = None self.disconnected = False self.disconnection_raised = False self.connect_time = None self.idle_time = time.time() self.send(of.ofp_hello()) self.original_ports = PortCollection() self.ports = PortCollection() self.ports._chain = self.original_ports
def __init__(self, sock): self._previous_stats = [] self.ofnexus = _dummyOFNexus self.sock = sock self.buf = '' Connection.ID += 1 self.ID = Connection.ID # TODO: dpid and features don't belong here; they should be eventually # be in topology.switch self.dpid = None self.config = None #add by Tan self.features = None self.disconnected = False self.connect_time = None self.idle_time = time.time() self.send(of.ofp_hello()) self.original_ports = PortCollection() self.ports = PortCollection() self.ports._chain = self.original_ports self.phyports = [] #add by milktank try to save the data of ports
def process_hello(self, pkt): print("This is a [Hello packet]") pkt_hello = of.ofp_hello() pkt_hello.xid = 9999 self.s.send(pkt_hello.pack()) print("hello pkt sent...", pkt_hello.pack())