Hi,

If you are using OpenFlow 1.5, please confirm your OVS supports OpenFlow 1.5.
Only some newer version of OVS support OpenFlow 1.5 (some OpenFlow 1.5 features
seems not be supported yet though).
You can test the support status by checking whether
  $ ryu-manager ryu/app/simple_switch_15.py --verbose
can transfer "ping" packets between your hosts or not.

With OVS version 2.9.0, I can send Packet-Out with the following code.

$ git diff
diff --git a/ryu/app/simple_switch_15.py b/ryu/app/simple_switch_15.py
index 6a86ba7..f3503bf 100644
--- a/ryu/app/simple_switch_15.py
+++ b/ryu/app/simple_switch_15.py
@@ -21,6 +21,9 @@ from ryu.ofproto import ofproto_v1_5
 from ryu.lib.packet import packet
 from ryu.lib.packet import ethernet
 from ryu.lib.packet import ether_types
+from ryu.lib.packet import ipv4
+from ryu.lib.packet import in_proto
+from ryu.lib.packet import tcp


 class SimpleSwitch15(app_manager.RyuApp):
@@ -48,6 +51,39 @@ class SimpleSwitch15(app_manager.RyuApp):
                                           ofproto.OFPCML_NO_BUFFER)]
         self.add_flow(datapath, 0, match, actions)

+        actions_out = [parser.OFPActionOutput(1)]
+        pkt = packet.Packet()
+        pkt.add_protocol(
+            ethernet.ethernet(
+                dst='08:2e:5f:2f:70:e2',
+                src='d4:85:64:17:ea:15',
+                ethertype=ether_types.ETH_TYPE_IP,
+            )
+        )
+        pkt.add_protocol(
+            ipv4.ipv4(
+                dst='192.168.1.1',
+                src='192.168.1.2',
+                proto=in_proto.IPPROTO_TCP,
+            )
+        )
+        pkt.add_protocol(
+            tcp.tcp(
+                src_port=50001,
+                dst_port=50002,
+            )
+        )
+        pkt.add_protocol(
+            b'foobar'
+        )
+        pkt.serialize()
+        match_out = parser.OFPMatch(in_port=2)
+        out = parser.OFPPacketOut(
+            datapath=datapath,
+            buffer_id=ofproto.OFP_NO_BUFFER,
+            match=match_out, actions=actions_out, data=pkt.data)
+        datapath.send_msg(out)
+
     def add_flow(self, datapath, priority, match, actions):
         ofproto = datapath.ofproto
         parser = datapath.ofproto_parser


Thanks,
Iwase


On 2018年03月29日 02:30, Alvaro Jimenez Moreno wrote:
Hi Iwase, thanks for your response,

Im using OpenFlow 1.5. I tried to create an ethernet packet as you mentioned but no packet is sent by the switch. I dont really know what im doing wrong. I just want to send a packet from datapath_id == 233669375027733 to datapath_id == 8995258462434.  Here's the code with the ethernet frame and header:

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

         match_miss = parser.OFPMatch()
         actions_miss = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER,
                                                ofproto.OFPCML_NO_BUFFER)]
         self.add_flow(datapath, 0, match_miss, actions_miss)

         actions_out = [parser.OFPActionOutput(1)]
         #self.add_flow(datapath, 1, match_2, actions_out)
         if msg.datapath_id == 233669375027733:
            match_cpd = parser.OFPMatch(in_port=1, eth_dst='08:2e:5f:2f:70:e2', eth_src='d4:85:64:17:ea:15',)
             self.add_flow(datapath, 1, match_cpd, actions_out)
         elif msg.datapath_id == 8995258462434:
            match_srem = parser.OFPMatch(in_port=1, eth_dst='d4:85:64:17:ea:15', eth_src='08:2e:5f:2f:70:e2')
             actions_srem = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER,
                                                    ofproto.OFPCML_NO_BUFFER)]
             self.add_flow(datapath, 1, match_srem, actions_srem)
         #I just send the packet from datapath_id == 233669375027733
         if msg.datapath_id == 233669375027733:
             p = packet.Packet()
            eth = ethernet.ethernet(dst='08:2e:5f:2f:70:e2', src='d4:85:64:17:ea:15', ethertype=0x0800)
             p.add_protocol(eth)
             p.serialize()
             match_out = parser.OFPMatch(in_port=1)
             out = parser.OFPPacketOut(datapath=msg.datapath,
                                     buffer_id=ofproto.OFP_NO_BUFFER,
                                    match=match_out, actions=actions_out, data=p.data)
             datapath.send_msg(out)


Thanks in advance.


2018-03-23 0:29 GMT+01:00 Iwase Yusuke <iwase.yusu...@gmail.com <mailto:iwase.yusu...@gmail.com>>:

    Hi Alvaro,

    According to the OpenFlow Spec 1.3, the data field of OFPPacketOut must be 
an
    Ethernet frame and I think you need to add also Ethernet header using
    "ethernet.ethernet" class.
    
http://osrg.github.io/ryu-book/en/html/packet_lib.html#generation-of-packets-serialization
    
<http://osrg.github.io/ryu-book/en/html/packet_lib.html#generation-of-packets-serialization>

    > p = packet.Packet()
    > ip = ipv4.ipv4(src='172.16.10.10', dst='172.16.10.20')
    > p.add_protocol(ip)
    > p.serialize()

     From your code, you seems to add only IPv4 header and no Ethernet header.

    Thanks,
    Iwase



    On 2018年03月23日 01:22, Alvaro Jimenez Moreno wrote:


        Hi, Im having some issues to send a packet out message between 2 ovs. Im
        have 3 PCs. 2 of them act like an ovs and the third one has the Ryu
        controller. Im have a vlan (vid=44) por signal traffic between both ovs
        and the controller and a vlan (vid=10) just for transport between both
        ovs. I also have the 3 PCs physically connected by a Cisco Catalyst 2960
        switch. Im figuring out how to send a packet out from one ovs
        (172.16.10.10) to the other ovs (172.16.10.20) without receiving a
        packet in message first. Now im sending the packet out in the switch
        features handler as follows:

        Switch features handler:

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

        match_miss = parser.OFPMatch()
        actions_miss = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER,
        ofproto.OFPCML_NO_BUFFER)]

        self.add_flow(datapath, 0, match_miss, actions_miss)
        match_2 = parser.OFPMatch(in_port=1, eth_type=0x800,
        ipv4_dst='172.16.10.20')

        actions_out = [parser.OFPActionOutput(port=1)]
        self.add_flow(datapath, 1, match_2, actions_out)

        #I send the packet out just from one ovs:
        if msg.datapath_id == 233669375027733:
        p = packet.Packet()
        ip = ipv4.ipv4(src='172.16.10.10', dst='172.16.10.20')
        p.add_protocol(ip)
        p.serialize()
        match_out = parser.OFPMatch(in_port=1)
        out = parser.OFPPacketOut(datapath=msg.datapath,
        buffer_id=ofproto.OFP_NO_BUFFER,
        match=match_out, actions=actions_out, data=p.data)
        datapath.send_msg(out)

        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,
        match=match, instructions=inst)
        datapath.send_msg(mod)

        Packet in handler:

        @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
        def packet_in_handler(self, ev):
        msg = ev.msg
        dp = msg.datapath
        ofp = dp.ofproto

        if msg.reason == ofp.OFPR_TABLE_MISS:
        reason = 'TABLE MISS'
        elif msg.reason == ofp.OFPR_APPLY_ACTION:
        reason = 'APPLY ACTION'
        elif msg.reason == ofp.OFPR_INVALID_TTL:
        reason = 'INVALID TTL'
        elif msg.reason == ofp.OFPR_ACTION_SET:
        reason = 'ACTION SET'
        elif msg.reason == ofp.OFPR_GROUP:
        reason = 'GROUP'
        elif msg.reason == ofp.OFPR_PACKET_OUT:
        reason = 'PACKET OUT'
        else:
        reason = 'unknown'

        if reason == 'PACKET OUT':
        self.logger.debug('OFPPacketIn received: '
        'buffer_id=%x total_len=%d reason=%s '
        'table_id=%d cookie=%d match=%s ',
        msg.buffer_id, msg.total_len, reason,
        msg.table_id, msg.cookie, msg.match)
        self.logger.debug('DATAPATH ADDRESS:%s', dp.address)

        I never recieve a packet in message due o a packet out message. Any help
        will be appreciated.

        Thanks in advance.



        
------------------------------------------------------------------------------
        Check out the vibrant tech community on one of the world's most
        engaging tech sites, Slashdot.org! http://sdm.link/slashdot



        _______________________________________________
        Ryu-devel mailing list
        Ryu-devel@lists.sourceforge.net <mailto:Ryu-devel@lists.sourceforge.net>
        https://lists.sourceforge.net/lists/listinfo/ryu-devel
        <https://lists.sourceforge.net/lists/listinfo/ryu-devel>




------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot



_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to