add_flow && actions=CONTROLLER:65535

 

    @set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
    def switch_features_handler(self, ev):
        datapath = ev.msg.datapath
        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser

        # install table-miss flow entry
        #
        # We specify NO BUFFER to max_len of the output action due to
        # OVS bug. At this moment, if we specify a lesser number, e.g.,
        # 128, OVS will send Packet-In with invalid buffer_id and
        # truncated packet data. In that case, we cannot output packets
        # correctly.

        match = parser.OFPMatch()
        actions = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER,
                                          ofproto.OFPCML_NO_BUFFER)]
        self.add_flow(datapath, 0, match, actions)
        self.logger.info("switch:%s connected", datapath.id)

 

    def add_flow(self, datapath, priority, match, actions):
        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser

        inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
                                             actions)]

        mod = parser.OFPFlowMod(datapath=datapath, priority=priority,
                                idle_timeout=5, hard_timeout=15,
                                match=match, instructions=inst)
        datapath.send_msg(mod)

 

from mininet.topo import Topo
class MininetTopo(Topo):
    def __init__(self,**opts):
        Topo.__init__(self, **opts)
        host1 = self.addHost('h1')
        host2 = self.addHost('h2')
        host3 = self.addHost('h3')
        host4 = self.addHost('h4')
    
        self.switch = {}
        for s in range(1,5):
            self.switch[s-1] = self.addSwitch('s%s' %(s))
        self.addLink(self.switch[0], self.switch[1])
        self.addLink(self.switch[0], self.switch[2])
        self.addLink(self.switch[0], self.switch[3])
            #Adding host
        self.addLink(self.switch[0], host1)
        self.addLink(self.switch[1], host2)
        self.addLink(self.switch[2], host3)
        self.addLink(self.switch[3], host4)
        
topos = {'group':(lambda:MininetTopo())}

 

[root@kunpeng82 devuser]# ovs-ofctl dump-flows s1
[root@kunpeng82 devuser]# ovs-ofctl dump-flows s2
[root@kunpeng82 devuser]# ovs-ofctl dump-flows s3
[root@kunpeng82 devuser]# ovs-ofctl dump-flows s4

 

更改add_flow

    def add_flow(self, datapath, priority, match, actions, buffer_id=None):
        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser

        inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
                                             actions)]
        if buffer_id:
            mod = parser.OFPFlowMod(datapath=datapath, buffer_id=buffer_id,
                                    priority=priority, match=match,
                                    instructions=inst)
        else:
            mod = parser.OFPFlowMod(datapath=datapath, priority=priority,
                                    match=match, instructions=inst)
        datapath.send_msg(mod)
[root@kunpeng82 devuser]# ovs-ofctl dump-flows s4
 cookie=0x0, duration=12.013s, table=0, n_packets=1, n_bytes=42, priority=0 actions=CONTROLLER:65535
[root@kunpeng82 devuser]# ovs-ofctl dump-flows s3
 cookie=0x0, duration=3886.590s, table=0, n_packets=3, n_bytes=210, priority=1,ipv6 actions=drop
 cookie=0x0, duration=4445.644s, table=0, n_packets=2, n_bytes=112, priority=0 actions=CONTROLLER:65535
[root@kunpeng82 devuser]# ovs-ofctl dump-flows s2
 cookie=0x0, duration=4442.220s, table=0, n_packets=11, n_bytes=1022, priority=1,in_port="s2-eth2",dl_dst=aa:68:d6:e5:4e:6c actions=output:"s2-eth1"
 cookie=0x0, duration=4442.213s, table=0, n_packets=10, n_bytes=924, priority=1,in_port="s2-eth1",dl_dst=ee:d4:36:57:e2:8b actions=output:"s2-eth2"
 cookie=0x0, duration=3891.124s, table=0, n_packets=3, n_bytes=210, priority=1,ipv6 actions=drop
 cookie=0x0, duration=4450.179s, table=0, n_packets=4, n_bytes=252, priority=0 actions=CONTROLLER:65535
[root@kunpeng82 devuser]# ovs-ofctl dump-flows s1
 cookie=0x0, duration=4446.588s, table=0, n_packets=11, n_bytes=1022, priority=1,in_port="s1-eth1",dl_dst=aa:68:d6:e5:4e:6c actions=output:"s1-eth4"
 cookie=0x0, duration=4446.585s, table=0, n_packets=10, n_bytes=924, priority=1,in_port="s1-eth4",dl_dst=ee:d4:36:57:e2:8b actions=output:"s1-eth1"
 cookie=0x0, duration=4182.215s, table=0, n_packets=5, n_bytes=350, priority=1,ipv6 actions=drop
 cookie=0x0, duration=4454.553s, table=0, n_packets=4, n_bytes=252, priority=0 actions=CONTROLLER:65535
[root@kunpeng82 devuser]# 

 

posted on 2020-06-01 14:15  tycoon3  阅读(508)  评论(0)    收藏  举报

导航