[pox-dev] Installing SPF in Switches

Muhammad Furqan Gagan furqan.gagan at gmail.com
Mon Nov 11 21:48:37 PST 2013


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"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.noxrepo.org/pipermail/pox-dev-noxrepo.org/attachments/20131111/881ae59e/attachment.htm>


More information about the pox-dev mailing list