def switch_feature_handler(self, event): dpid = event.msg.datapath_id try: switch = self.dpid_to_switch[dpid] except KeyError: self.dpid_to_switch[dpid] = Switch(event.msg.datapath) switch = self.dpid_to_switch[dpid] for port_no, port in event.msg.ports.iteritems(): if port_no not in switch.ports: p = Port(port = port, dp = event.msg.datapath) switch.ports[port_no] = p p = switch.ports[port_no] if port_no == ofproto_v1_0.OFPP_LOCAL: switch.name = port.name.rstrip('\x00') else: # port.curr is a number of 32 bits, only used 12 bits in ovs # represents current features of the port. # LOCAL port doesn't have a cost value curr = port.curr & 0x7f # get last 7 bits p.cost = 64/curr print 'cost:', p.cost switch.update_from_config(self.switch_cfg) self.routing_algo.topology_last_update = time.time()
def switch_feature_handler(self, event): dpid = event.msg.datapath_id try: switch = self.dpid_to_switch[dpid] except KeyError: self.dpid_to_switch[dpid] = Switch(event.msg.datapath) switch = self.dpid_to_switch[dpid] for port_no, port in event.msg.ports.iteritems(): if port_no not in switch.ports: p = Port(port=port, dp=event.msg.datapath) switch.ports[port_no] = p p = switch.ports[port_no] if port_no == ofproto_v1_0.OFPP_LOCAL: switch.name = port.name.rstrip('\x00') else: # port.curr is a number of 32 bits, only used 12 bits in ovs # represents current features of the port. # LOCAL port doesn't have a cost value curr = port.curr & 0x7f # get last 7 bits p.cost = 64 / curr print 'cost:', p.cost switch.update_from_config(self.switch_cfg) self.routing_algo.topology_last_update = time.time()
def add_link(self, event): ''' Adds a link from port to to port ''' src_port = Port(port=event.link.src, peer=event.link.dst, is_edge=False) dst_port = Port(port=event.link.dst, peer=event.link.src, is_edge=False) self._update_port_link(src_port.dpid, src_port) self._update_port_link(dst_port.dpid, dst_port) self.pathfindinding_algo.topology_last_update = time.time()
def port_delete_handler(self, event): port = Port(event.port) try: switch = self.dpid_to_switch[port.dpid] del switch.ports[port.port_no] self.routing_algo.topology_last_update = time.time() except KeyError: pass
def add_port(self, port): ''' Adds a port to the topology ''' port = Port(port) switch = self.dpid_to_switch[port.dpid] switch.ports[port.port_no] = port self.pathfindinding_algo.topology_last_update = time.time()
def remove_port(self, port): ''' Removes a switch to the topology ''' port = Port(port) try: switch = self.dpid_to_switch[port.dpid] del switch.ports[port.port_no] self.pathfindinding_algo.topology_last_update = time.time() except KeyError: return
def port_add_handler(self, event): port = Port(event.port) switch = self.dpid_to_switch[port.dpid] switch.ports[port.port_no] = port switch.update_from_config(self.switch_cfg) self.routing_algo.topology_last_update = time.time()
def link_add_handler(self, event): src_port = Port(port=event.link.src, peer=event.link.dst) dst_port = Port(port=event.link.dst, peer=event.link.src) self._update_port_link(src_port.dpid, src_port) self._update_port_link(dst_port.dpid, dst_port) self.routing_algo.topology_last_update = time.time()