Fix first ping package packet loss
This commit is contained in:
37
example.py
37
example.py
@@ -200,8 +200,6 @@ class L3Switch(app_manager.RyuApp):
|
|||||||
# install a flow to avoid packet_in next time
|
# install a flow to avoid packet_in next time
|
||||||
if out_port != ofproto.OFPP_FLOOD:
|
if out_port != ofproto.OFPP_FLOOD:
|
||||||
match = parser.OFPMatch(in_port=in_port, eth_dst=frame.dst)
|
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
|
# verify if we have a valid buffer_id, if yes avoid to send both
|
||||||
# flow_mod & packet_out
|
# flow_mod & packet_out
|
||||||
if buffer_id != ofproto.OFP_NO_BUFFER:
|
if buffer_id != ofproto.OFP_NO_BUFFER:
|
||||||
@@ -222,27 +220,37 @@ class L3Switch(app_manager.RyuApp):
|
|||||||
parser = datapath.ofproto_parser
|
parser = datapath.ofproto_parser
|
||||||
|
|
||||||
if ipv4_pkt.dst in self.ip_to_mac[dpid]:
|
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]
|
dstMac = self.ip_to_mac[dpid][ipv4_pkt.dst]
|
||||||
|
out_port = self.mac_to_port[dpid][dstMac]
|
||||||
else:
|
else:
|
||||||
self.send_arp(datapath, 1, self.MAC_ADDR, ipv4_pkt.src, "FF:FF:FF:FF:FF:FF", ipv4_pkt.dst, ofproto.OFPP_FLOOD)
|
# Send an arp request and define mac and port
|
||||||
return
|
# 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)
|
||||||
|
|
||||||
out_port = self.mac_to_port[dpid][dstMac]
|
# 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
|
actions = [parser.OFPActionDecNwTtl(), #decrease TTL count
|
||||||
parser.OFPActionSetField(eth_src=self.MAC_ADDR), # set own mac as source
|
parser.OFPActionSetField(eth_src=self.MAC_ADDR), # set own mac as source
|
||||||
parser.OFPActionSetField(eth_dst=dstMac), # set dst from arp request
|
parser.OFPActionSetField(eth_dst=dstMac), # set dst from arp request
|
||||||
parser.OFPActionOutput(out_port)] # forward packet through out_port
|
parser.OFPActionOutput(out_port)] # forward packet through out_port
|
||||||
|
|
||||||
# install a flow to avoid packet_in next time
|
# Only install a flow if we#re in the first case (specific mac and out_port)
|
||||||
match = parser.OFPMatch(in_port=in_port, ipv4_dst=ipv4_pkt.dst, eth_type=0x0800) #onlz match ipv4 packets
|
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
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
# 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
|
data = None
|
||||||
if buffer_id == ofproto.OFP_NO_BUFFER:
|
if buffer_id == ofproto.OFP_NO_BUFFER:
|
||||||
data = packet.data
|
data = packet.data
|
||||||
@@ -301,6 +309,7 @@ class L3Switch(app_manager.RyuApp):
|
|||||||
if icmp_pkt:
|
if icmp_pkt:
|
||||||
self.do_icmp(datapath, in_port, eth, ipv4_pkt, icmp_pkt)
|
self.do_icmp(datapath, in_port, eth, ipv4_pkt, icmp_pkt)
|
||||||
else:
|
else:
|
||||||
|
# forward the package into a different subnet
|
||||||
self.do_l3_switch(datapath, dpid, pkt, eth, ipv4_pkt, in_port, msg.buffer_id)
|
self.do_l3_switch(datapath, dpid, pkt, eth, ipv4_pkt, in_port, msg.buffer_id)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user