进一步拓展了一下实验(二)
实验拓扑:
实验目的:
使h1-h4的 icmp request packet从eth1发出,沿着h1eth1-sweth2-sweth1-h3eth1-h3eth2-h43th1路线转发,并将sweth3/sweth1收到的reply报文从sweth2转发给h1eth1。
#现在用的request的转发路线是h1-sw-h3-h4同样的也可以设置h1-sw-h2-h4这条转发路线,和现在设置的h1-sw-h3-h4这条路线用的方法没有区别(在拓扑中h2和h3处于等价的地位)
实验代码:
from ryu.base import app_manager
from ryu.controller import ofp_event
from ryu.controller.handler import CONFIG_DISPATCHER, MAIN_DISPATCHER
from ryu.controller.handler import set_ev_cls
from ryu.ofproto import ofproto_v1_3
from ryu.ofproto import ether
from ryu.ofproto import inet
from ryu.lib.packet import packet
from ryu.lib.packet import ethernet
from ryu.lib.packet import arp
from ryu.lib.packet import ipv4
from ryu.lib.packet import icmp
class ExampleSwitch13(app_manager.RyuApp):
OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]
def __init__(self, *args, **kwargs):
super(ExampleSwitch13, self).__init__(*args, **kwargs)
self.ip = {"h1e1":"10.10.1.1", "vp2":"10.10.1.2", "h2e1":"10.10.2.1","vp3":"10.10.2.2","h3e1":"10.10.3.1","vp1":"10.10.3.2","h2e2":"10.10.4.1","h4e1":"10.10.4.2","h3e2":"10.10.4.3"}
self.mac = {"h1e1":"02:4c:45:99:70:70", "vp2":"da:e3:c8:d1:53:14", "h2e1":"02:96:11:ae:a0:b3","vp3":"72:1a:15:7d:3f:de","h3e1":"02:27:d6:b4:a3:35","vp1":"ce:09:83:81:42:e4","h2e2":"02:51:13:7e:2e:9e","h3e2":"02:50:01:cb:db:42","h4e1":"02:9a:b9:85:36:ec"}
# h1-vp2 h2e1-vp3 h3e1-vp1
self.gw_mac = {}
#arp: 直接发给发arp请求的主机对应网关的mac
self.gw_mac[self.ip["h1e1"]] = self.mac["vp2"]
self.gw_mac[self.ip["h2e1"]] = self.mac["vp3