Fix first ping package packet loss
This commit is contained in:
21
example.py
21
example.py
@@ -200,8 +200,6 @@ class L3Switch(app_manager.RyuApp):
|
||||
# install a flow to avoid packet_in next time
|
||||
if out_port != ofproto.OFPP_FLOOD:
|
||||
match = parser.OFPMatch(in_port=in_port, eth_dst=frame.dst)
|
||||
self.logger.info(actions)
|
||||
self.logger.info(match)
|
||||
# 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:
|
||||
@@ -222,17 +220,26 @@ class L3Switch(app_manager.RyuApp):
|
||||
parser = datapath.ofproto_parser
|
||||
|
||||
if ipv4_pkt.dst in self.ip_to_mac[dpid]:
|
||||
# GEt mac and port of the given destination
|
||||
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[dpid][dstMac]
|
||||
else:
|
||||
# Send an arp request and define mac and port
|
||||
# so we're able to apply the following actions
|
||||
# on the packet.
|
||||
out_port = ofproto.OFPP_FLOOD
|
||||
dstMac = "FF:FF:FF:FF:FF:FF"
|
||||
self.send_arp(datapath, 1, self.MAC_ADDR, ipv4_pkt.src, dstMac, ipv4_pkt.dst, out_port)
|
||||
|
||||
# Actions are applied in the same order as defined in the list.
|
||||
# OFPActionOutput terminates the chain. So this call should be the last action.
|
||||
actions = [parser.OFPActionDecNwTtl(), #decrease TTL count
|
||||
parser.OFPActionSetField(eth_src=self.MAC_ADDR), # set own mac as source
|
||||
parser.OFPActionSetField(eth_dst=dstMac), # set dst from arp request
|
||||
parser.OFPActionOutput(out_port)] # forward packet through out_port
|
||||
|
||||
# Only install a flow if we#re in the first case (specific mac and out_port)
|
||||
if ipv4_pkt.dst in self.ip_to_mac[dpid]:
|
||||
# install a flow to avoid packet_in next time
|
||||
match = parser.OFPMatch(in_port=in_port, ipv4_dst=ipv4_pkt.dst, eth_type=0x0800) #onlz match ipv4 packets
|
||||
|
||||
@@ -243,6 +250,7 @@ class L3Switch(app_manager.RyuApp):
|
||||
return
|
||||
else:
|
||||
self.add_flow(datapath, 1, match, actions)
|
||||
|
||||
data = None
|
||||
if buffer_id == ofproto.OFP_NO_BUFFER:
|
||||
data = packet.data
|
||||
@@ -301,6 +309,7 @@ class L3Switch(app_manager.RyuApp):
|
||||
if icmp_pkt:
|
||||
self.do_icmp(datapath, in_port, eth, ipv4_pkt, icmp_pkt)
|
||||
else:
|
||||
# forward the package into a different subnet
|
||||
self.do_l3_switch(datapath, dpid, pkt, eth, ipv4_pkt, in_port, msg.buffer_id)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user