def _handle_keepalive_handler(cls, ofnexus): # Construct OF Echo Request packet er = of.ofp_echo_request().pack() t = time.time() dead = [] for dpid, conn in ofnexus.connections.iteritems(): if t - conn.idle_time > (cls._interval + cls._switch_timeout): dead.append(conn) continue conn.send(er) for conn in dead: conn.disconnect("Connection: %s has reached timeout: %s!" % (conn, cls._switch_timeout))
def _handle_timer(ofnexus): er = of.ofp_echo_request().pack() count = len(ofnexus.connections) t = time.time() dead = [] for dpid, con in ofnexus.connections.items(): if t - con.idle_time > (_interval + _switch_timeout): dead.append(con) continue con.send(er) for con in dead: con.disconnect("timed out")
def _handle_timer (ofnexus): er = of.ofp_echo_request().pack() count = len(ofnexus.connections) t = time.time() dead = [] for dpid,con in ofnexus.connections.iteritems(): if t - con.idle_time > (_interval+_switch_timeout): dead.append(con) continue con.send(er) for con in dead: con.disconnect("timed out")
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 _handle_keepalive_handler(cls, ofnexus): """ Handles keepalive event. :param ofnexus: event originator object :type ofnexus: :class:`pox.openflow.OpenFlowNexus` :return: None """ # Construct OF Echo Request packet er = of.ofp_echo_request().pack() t = time.time() dead = [] for dpid, conn in ofnexus.connections.iteritems(): if t - conn.idle_time > (cls._interval + cls._switch_timeout): dead.append(conn) continue conn.send(er) for conn in dead: conn.disconnect("Connection: %s has reached timeout: %s!" % (conn, cls._switch_timeout))
def loop(self, steps=None): self.running = True end_time = self.logical_time + steps if steps else sys.maxint while self.running and self.logical_time < end_time: self.logical_time += 1 self.trigger_events() msg.event("Round %d completed." % self.logical_time) if self.interactive: # TODO: print out the state of the network at each timestep? Take a # verbose flag.. self.invariant_check_prompt() self.dataplane_trace_prompt() answer = msg.raw_input('Continue to next round? [Yn]').strip() if answer != '' and answer.lower() != 'y': self.stop() break else: # not self.interactive if (self.logical_time % self.check_interval) == 0: # Time to run correspondence! # spawn a thread for running correspondence. Make sure the controller doesn't # think we've gone idle though: send OFP_ECHO_REQUESTS every few seconds # TODO: this is a HACK def do_correspondence(): any_policy_violations = self.invariant_checker.check_correspondence(self.live_switches, self.live_links, self.access_links) if any_policy_violations: msg.fail("There were policy-violations!") else: msg.interactive("No policy-violations!") thread = threading.Thread(target=do_correspondence) thread.start() while thread.isAlive(): for switch in self.live_switches: # connection -> deferred io worker -> io worker switch.send(of.ofp_echo_request().pack()) thread.join(2.0) if self.dataplane_trace and (self.logical_time % self.trace_interval) == 0: self.inject_trace_event() time.sleep(self.delay)
def send(): con.send(ofp_echo_request()) #print 'send echo request' #global t #Notice: use global variable! t = threading.Timer(2.0, send) t.start()
def _handle_timer (ofnexus): er = of.ofp_echo_request().pack() count = len(ofnexus._connections) ##if count != 0: log.debug("Sending echo requests") for dpid,con in ofnexus._connections.iteritems(): con.send(er)