Update example.py
Currently not working.
This commit is contained in:
33
example.py
33
example.py
@@ -214,6 +214,38 @@ class L3Switch(app_manager.RyuApp):
|
|||||||
in_port=in_port, actions=actions, data=data)
|
in_port=in_port, actions=actions, data=data)
|
||||||
datapath.send_msg(out)
|
datapath.send_msg(out)
|
||||||
|
|
||||||
|
def do_l3_switch(self, datapath, dpid, packet, frame, ipv4_pkt, in_port, buffer_id=None):
|
||||||
|
ofproto = datapath.ofproto
|
||||||
|
parser = datapath.ofproto_parser
|
||||||
|
|
||||||
|
if ipv4_pkt.dst in self.ip_to_mac[dpid]:
|
||||||
|
dstMac = self.ip_to_mac[dpid][ipv4_pkt.dst]
|
||||||
|
else:
|
||||||
|
self.send_arp(datapath, 1, self.MAC_ADDR, ipv4_pkt.src, "FF:FF:FF:FF:FF:FF", ipv4_pkt.dst, ofproto.OFPP_FLOOD)
|
||||||
|
return
|
||||||
|
|
||||||
|
out_port = self.mac_to_port[dstMac]
|
||||||
|
actions = [parser.OFPActionSetDlSrc(ipv4_pkt.src), parser.OFPActionSetDlDst(ipv4_pkt.dst), parser.OFPActionOutput(out_port)]
|
||||||
|
|
||||||
|
# install a flow to avoid packet_in next time
|
||||||
|
match = parser.OFPMatch(dl_src=ipv4_pkt.src, dl_dst=ipv4_pkt.dst)
|
||||||
|
# verify if we have a valid buffer_id, if yes avoid to send both
|
||||||
|
# flow_mod & packet_out
|
||||||
|
if buffer_id != ofproto.OFP_NO_BUFFER:
|
||||||
|
self.add_flow(datapath, 1, match, actions, buffer_id)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
self.add_flow(datapath, 1, match, actions)
|
||||||
|
data = None
|
||||||
|
if buffer_id == ofproto.OFP_NO_BUFFER:
|
||||||
|
data = packet.data
|
||||||
|
|
||||||
|
out = parser.OFPPacketOut(datapath=datapath, buffer_id=buffer_id,
|
||||||
|
in_port=in_port, actions=actions, data=data)
|
||||||
|
datapath.send_msg(out)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
|
@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
|
||||||
def _packet_in_handler(self, ev):
|
def _packet_in_handler(self, ev):
|
||||||
# If you hit this you might want to increase
|
# If you hit this you might want to increase
|
||||||
@@ -269,6 +301,7 @@ class L3Switch(app_manager.RyuApp):
|
|||||||
pkt.get_protocols(ethernet.ethernet)[0].dst = dstMac
|
pkt.get_protocols(ethernet.ethernet)[0].dst = dstMac
|
||||||
pkt.get_protocols(ethernet.ethernet)[0].src = self.MAC_ADDR
|
pkt.get_protocols(ethernet.ethernet)[0].src = self.MAC_ADDR
|
||||||
port = self.mac_to_port[dpid][dstMac]
|
port = self.mac_to_port[dpid][dstMac]
|
||||||
|
self.do_l3_switch(datapath, dpid, pkt, eth, ipv4_pkt, in_port, msg.buffer_id)
|
||||||
#self.logger.info(port)
|
#self.logger.info(port)
|
||||||
self.send_packet(datapath, port, pkt)
|
self.send_packet(datapath, port, pkt)
|
||||||
pass
|
pass
|
||||||
|
Reference in New Issue
Block a user