Add comments and cleanup
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
# Abgabe von:
|
||||
# Jutta Seth, Janek Schoffit, Eva Högner
|
||||
# Problem 1.2 (Simple IP routing)
|
||||
from ryu.base import app_manager
|
||||
from ryu.controller import ofp_event
|
||||
from ryu.controller.handler import CONFIG_DISPATCHER, MAIN_DISPATCHER
|
||||
|
@@ -1,3 +1,6 @@
|
||||
# Abgabe von:
|
||||
# Jutta Seth, Janek Schoffit, Eva Högner
|
||||
# Problem 1.3 (IP Router for IPv4)
|
||||
from ryu.base import app_manager
|
||||
from ryu.controller import ofp_event
|
||||
from ryu.controller.handler import CONFIG_DISPATCHER, MAIN_DISPATCHER
|
||||
|
@@ -1,3 +1,6 @@
|
||||
# Abgabe von:
|
||||
# Jutta Seth, Janek Schoffit, Eva Högner
|
||||
# Problem 1.4 (Packet-based IP Anycast)
|
||||
from ryu.base import app_manager
|
||||
from ryu.controller import ofp_event
|
||||
from ryu.controller.handler import CONFIG_DISPATCHER, MAIN_DISPATCHER
|
||||
@@ -23,8 +26,10 @@ class L3Switch(app_manager.RyuApp):
|
||||
self.mac_to_port = {}
|
||||
self.port_to_mac = {}
|
||||
self.ip_to_mac = {}
|
||||
|
||||
# Define the ports for anycast round robin
|
||||
self.anycastPorts = [1, 3, 4]
|
||||
self.anycastIndex = 0
|
||||
self.anycastIndex = 0 # round robin index for the ports array
|
||||
|
||||
@set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
|
||||
def switch_features_handler(self, ev):
|
||||
@@ -190,18 +195,10 @@ class L3Switch(app_manager.RyuApp):
|
||||
else:
|
||||
out_port = ofproto.OFPP_FLOOD
|
||||
|
||||
actions = [parser.OFPActionOutput(out_port)]
|
||||
# add_flow removed, otherwise the controller wouldn't receive new packets
|
||||
# for the anycast switching.
|
||||
|
||||
# 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)
|
||||
# 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)
|
||||
actions = [parser.OFPActionOutput(out_port)]
|
||||
data = None
|
||||
if buffer_id == ofproto.OFP_NO_BUFFER:
|
||||
data = packet.data
|
||||
@@ -210,6 +207,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
|
||||
@@ -221,8 +219,10 @@ class L3Switch(app_manager.RyuApp):
|
||||
ofproto = datapath.ofproto
|
||||
parser = datapath.ofproto_parser
|
||||
|
||||
# Select a port
|
||||
port = self.anycast_next()
|
||||
|
||||
# Send the package without adding a flow
|
||||
packet.get_protocols(ethernet.ethernet)[0].dst = self.port_to_mac[dpid][str(port)]
|
||||
self.send_packet(datapath, port, packet)
|
||||
|
||||
@@ -273,6 +273,7 @@ class L3Switch(app_manager.RyuApp):
|
||||
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, msg.buffer_id)
|
||||
return
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user