Add comments and cleanup

This commit is contained in:
2022-05-29 18:48:24 +00:00
parent c67d2041f9
commit 92e82b93fb
4 changed files with 26 additions and 16 deletions

View File

@@ -1,3 +1,6 @@
# Abgabe von:
# Jutta Seth, Janek Schoffit, Eva Högner
# Problem 1.4 (Flow-based IP Anycast)
from ryu.base import app_manager
from ryu.controller import ofp_event
from ryu.controller.handler import CONFIG_DISPATCHER, MAIN_DISPATCHER
@@ -210,6 +213,7 @@ class L3Switch(app_manager.RyuApp):
in_port=in_port, actions=actions, data=data)
datapath.send_msg(out)
# Get the next port where a package should be forwarded
def anycast_next(self):
if self.anycastIndex >= 2:
self.anycastIndex = 0
@@ -222,18 +226,18 @@ class L3Switch(app_manager.RyuApp):
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
# Retrieve tcp tuple
tcp_pkt = packet.get_protocol(tcp.tcp)
tcp_src = tcp_pkt.src_port
tcp_dst = tcp_pkt.dst_port
self.logger.info("src: %s, dst: %s", tcp_src, tcp_dst)
# Get the anycast port
port = self.anycast_next()
actions = [parser.OFPActionSetField(eth_dst = self.port_to_mac[dpid][str(port)]),
parser.OFPActionOutput(port)]
match = parser.OFPMatch(eth_type=0x0800, ipv4_src=ipv4_pkt.src, ip_proto=6, tcp_src=tcp_src, ipv4_dst=ipv4_pkt.dst, tcp_dst=tcp_dst)
#match = parser.OFPMatch(in_port=in_port, eth_dst=frame.dst, tcp_src=tcp_src)
if buffer_id != ofproto.OFP_NO_BUFFER:
self.add_flow(datapath, 1, match, actions, buffer_id)
@@ -280,7 +284,6 @@ class L3Switch(app_manager.RyuApp):
self.ip_to_mac.setdefault(dpid, {})
self.logger.info("packet in dpid: %s, src: %s, dest: %s, in_port: %s", dpid, src, dst, in_port)
#self.logger.info(pkt)
#learn mac to port mapping
if src not in self.mac_to_port[dpid]:
@@ -291,13 +294,13 @@ class L3Switch(app_manager.RyuApp):
return
if eth.ethertype == ether_types.ETH_TYPE_IP:
ipv4_pkt = pkt.get_protocol(ipv4.ipv4)
#check if packet is for this switch
if ipv4_pkt.dst == self.IP_ADDR:
icmp_pkt = pkt.get_protocol(icmp.icmp)
if icmp_pkt:
self.do_icmp(datapath, in_port, eth, ipv4_pkt, icmp_pkt)
# Do anycast if the package contains the anycast dst-IP
if ipv4_pkt.dst == "10.0.0.100":
self.do_anycast(datapath, dpid, pkt, eth, in_port, ipv4_pkt, msg.buffer_id)
return