Dear all:
I recent read the RYU book and try to write some simple code to test
the function of OpenFlow1.3. In the RYU book page
84<http://osrg.github.io/ryu-book/en/html/packet_lib.html#application-examples>,
it describes how to use PacketIn and PacketOut message to make the
controller response the ICMP echo.
I reference the RYU book to write an app to make the controller become
"A man in the middle (not packet mirror)". I hope that every packet which
pass through the OpenFlow switch (I use OpenvSwitch ) will first be sent to
the controller and return to the OpenFlow switch. Any device under the
OpenvSwitch will not notify that their packets go through the controller.
In the OpenvSwitch side, I captured both PacketIn and PacketOut message
by using wireshark. However I did not capture the original packet which
should be sent out to the uplink. The following is my code. Can any please
help me to know what it is wrong?
#-*- coding: utf-8 -*-
> import logging
> import struct
> from ryu.base import app_manager
> from ryu.controller import ofp_event
> from ryu.controller.handler import MAIN_DISPATCHER, CONFIG_DISPATCHER
> from ryu.controller.handler import set_ev_cls
> from ryu.ofproto import ofproto_v1_3
> from ryu.controller import dpset
> from ryu.lib.packet import packet
> from ryu.lib.packet import ethernet
> from ryu.lib.packet import ipv4,tcp,udp
> class SecureArchitecture(app_manager.RyuApp):
> OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]
> _CONTEXTS = {'dpset': dpset.DPSet}
> def __init__(self, *args, **kwargs):
> super(SecureArchitecture, self).__init__(*args, **kwargs)
>
> @set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
> def switch_features_handler(self, ev):
> #Trigger when receive a PacketIn packet
>
> msg = ev.msg
> datapath = msg.datapath
> ofproto = datapath.ofproto
> parser = datapath.ofproto_parser
>
>
> match = parser.OFPMatch(in_port=1)
> actions = [parser.OFPActionOutput(ofproto.OFPP_NORMAL)]
> inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,actions)]
> mod = parser.OFPFlowMod(datapath=datapath, priority=1999,
> match=match, instructions=inst, table_id = 0)
> datapath.send_msg(mod)
>
> match = parser.OFPMatch(eth_type=0x800,
> ip_proto=1) #only send the icmp echo to the controller
> actions = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER)]
> inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,actions)]
> mod = parser.OFPFlowMod(datapath=datapath, priority=1000,
> match=match, instructions=inst, table_id = 0)
> datapath.send_msg(mod)
>
> match = parser.OFPMatch()
> actions = [parser.OFPActionOutput(ofproto.OFPP_NORMAL)]
> inst =
> [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,actions)]
> mod = parser.OFPFlowMod(datapath=datapath, priority=10,
> match=match, instructions=inst, table_id = 0)
> datapath.send_msg(mod)
>
> @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
> def _packet_in_handler(self, ev):
> #Trigger when switch remove a flow entry because of the timeout of a flow
> entry
> msg = ev.msg
> datapath = msg.datapath
> ofproto = datapath.ofproto
> parser = datapath.ofproto_parser
> port = msg.match['in_port']
> pkt = packet.Packet(data=msg.data)
>
> self.send_packet=(datapath, port, pkt)
>
>
> def send_packet(self, datapath, port, pkt):
> ofproto = datapath.ofproto
> parser = datapath.ofproto_parser
> pkt.serialize()
> self.logger.info("packet-out %s" % (pkt,))
> data = pkt.data
> actions = [parser.OFPActionOutput(port=1)] # 1 is the uplink port number
> of ovs
> out = parser.OFPPacketOut(datapath=datapath,
> buffer_id=ofproto.OFP_NO_BUFFER,
> in_port=ofproto.OFPP_CONTROLLER,
> actions=actions,
> data=data)
> datapath.send_msg(out)
With best regards,
Claudia
Apr. 12
------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel