Have you taken a look at the l2_multi and topo_proactive components? Both of them compute and install shortest paths.
-- Murphy On Nov 11, 2013, at 9:48 PM, Muhammad Furqan Gagan <[email protected]> wrote: > Hello … > > I am working on a controller which calculate shrtest path from a function i > have made and returns an array of switches in between source and destination > switches... When a packet is received i calculate their source and dpids and > calculate their shotest path. for example: for switch 1 and switch 7 there is > a shortest path [2,3,4,7] > Now i want to install flows for them > > > Currently I am doing this… It is sending the packet and installing flows but > I cant ping … I am new to POX so if you can explain it in bit easier way !! > Thanks > > > def _handle_PacketIn (self, event): > > def flood(): #floods the packet > > msg = of.ofp_packet_out() > msg.actions.append(of.ofp_action_output(port = of.OFPP_FLOOD)) > msg.data = packet_in.data > msg.in_port = in_port > self.connection.send(msg) > > > def drop():# drops the message > > if packet_in.buffer_id is not None: > > msg = of.ofp_packet_out() > msg.buffer_id = packet_in.buffer_id > > msg.in_port = in_port > self.connection.send(msg) > > > > packet = event.parsed > packet_in = event.ofp > in_port = event.port > #print in_port > dpid = event.dpid > > > > if packet.type == packet.LLDP_TYPE: > self.receive_topology_packet(dpid,in_port,packet) > > return > > > > self.host_table[packet.src] = in_port > > > if packet.dst.is_multicast: > flood() > return > > if packet.dst not in self.host_table: # check for unknown destination > > flood() > return > > else: > > print "%s" %(packet.src) > print "%s" %(packet.dst) > p_s = str(packet.src) > p_d = str(packet.dst) > > dpid_src = dpid > print "src dpid",dpid_src > for s in range(len(switch)): > > > if p_d[-1:] == str(switch[s]): > dpid_dst = switch[s] > print "dest dpid",dpid_dst > > best_route = [] > best_route = spf.shortest_path(dpid_src,dpid_dst) > best_route.reverse() > print best_route > > print " known" > > > msg = of.ofp_flow_mod() > > if not packet.type == packet.VLAN_TYPE: > print "attaching a vlan id" > msg.actions.append(of.ofp_action_vlan_vid(vlan_vid = > dpid_dst)) > > elif dpid_src == dpid_dst: > print "arived at destination striping vtag" > msg.actions.append(of.ofp_action_strip_vlan()) > > > > > if best_route: > if not best_route[0] == dpid_dst: > next_hop = best_route[0] > > > if not dpid_src== dpid_dst: > for p in topo[dpid_src]: > temp = topo[dpid_src][p] > if temp [0]== next_hop: # in topo[dpid_src][p]: > print"yes" > print"p",p > #dp,op = topo[dpid][p] > op = p > print "outport",op > else: > print"we r at destination" > op = self.host_table[packet.dst] > print "op" > > > print"sending flow" > msg = of.ofp_flow_mod() # installing flow > msg.match = of.ofp_match.from_packet(packet, in_port) > msg.idle_timeout = 10 > msg.hard_timeout = 30 > > msg.actions.append(of.ofp_action_output(port = op)) > msg.data = packet_in > > self.connection.send(msg) > > msg = of.ofp_packet_out() > msg.actions.append(of.ofp_action_output(port = op)) > msg.data = packet_in.data > msg.in_port = in_port > self.connection.send(msg) > print "flow sent"
