@@ -0,0 +1,2239 @@
+from ryu.base import app_manager%0Afrom ryu.controller import ofp_event%0Afrom ryu.controller.handler import MAIN_DISPATCHER, CONFIG_DISPATCHER%0Afrom ryu.controller.handler import set_ev_cls%0Afrom ryu.ofproto import ofproto_v1_3%0A%0A%0Aclass SimpleHub(app_manager.RyuApp):%0A    OFP_VERSIONS = %5Bofproto_v1_3.OFP_VERSION%5D%0A%0A    def __init__(self, *args, **kwargs):%0A        super(SimpleHub, self).__init__(*args, **kwargs)%0A%0A    def add_flow(self, datapath, priority, match, actions, buffer_id=None):%0A        ofproto = datapath.ofproto%0A        parser = datapath.ofproto_parser%0A%0A        inst = %5Bparser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,%0A                                             actions)%5D%0A        if buffer_id:%0A            mod = parser.OFPFlowMod(datapath=datapath, buffer_id=buffer_id,%0A                                    priority=priority, match=match,%0A                                    instructions=inst)%0A        else:%0A            mod = parser.OFPFlowMod(datapath=datapath, priority=priority,%0A                                    match=match, instructions=inst)%0A        datapath.send_msg(mod)%0A%0A    @set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)%0A    def switch_features_handler(self, ev):%0A        datapath = ev.msg.datapath%0A        ofproto = datapath.ofproto%0A        parser = datapath.ofproto_parser%0A%0A        match = parser.OFPMatch()%0A        actions = %5Bparser.OFPActionOutput(ofproto.OFPP_CONTROLLER,%0A                                          ofproto.OFPCML_NO_BUFFER)%5D%0A        self.add_flow(datapath, 0, match, actions)%0A%0A    @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)%0A    def packet_in_handler(self, ev):%0A        msg = ev.msg%0A        datapath = msg.datapath%0A        ofproto = datapath.ofproto%0A        parser = datapath.ofproto_parser%0A%0A        data = None%0A        if msg.buffer_id == ofproto.OFP_NO_BUFFER:%0A            data = msg.data%0A%0A        actions = %5Bparser.OFPActionOutput(ofproto.OFPP_FLOOD)%5D%0A        out = parser.OFPPacketOut(datapath=datapath,%0A                                  buffer_id=msg.buffer_id,%0A                                  in_port=msg.match%5B'in_port'%5D,%0A                                  actions=actions,%0A                                  data=data)%0A        datapath.send_msg(out)%0A

Add examples