summaryrefslogtreecommitdiffhomepage
path: root/tests/mininet/l2
diff options
context:
space:
mode:
Diffstat (limited to 'tests/mininet/l2')
-rw-r--r--tests/mininet/l2/mpls/PopMPLS_mpls.mn6
-rw-r--r--tests/mininet/l2/mpls/PushMPLS_ip.mn6
-rw-r--r--tests/mininet/l2/mpls/PushMPLS_mpls.mn6
-rw-r--r--tests/mininet/l2/mpls/test_mpls.py127
-rw-r--r--tests/mininet/l2/vlan/PopVLAN_vlan.mn6
-rw-r--r--tests/mininet/l2/vlan/PopVLAN_vlanvlan.mn6
-rw-r--r--tests/mininet/l2/vlan/PushVLAN_icmp.mn6
-rw-r--r--tests/mininet/l2/vlan/test_vlan.py130
8 files changed, 293 insertions, 0 deletions
diff --git a/tests/mininet/l2/mpls/PopMPLS_mpls.mn b/tests/mininet/l2/mpls/PopMPLS_mpls.mn
new file mode 100644
index 00000000..45fa9f96
--- /dev/null
+++ b/tests/mininet/l2/mpls/PopMPLS_mpls.mn
@@ -0,0 +1,6 @@
+TEST_NAME=MPLS-PopMPLS
+DUMP_HOST=h2
+DUMP_IF=h2-eth0
+RYU_APP=test_mpls
+PCAP_MZ="-t tcp -M 80 -P $TEST_NAME -c 3 -r"
+PCAP_FILTER="! mpls && ip.proto==TCP"
diff --git a/tests/mininet/l2/mpls/PushMPLS_ip.mn b/tests/mininet/l2/mpls/PushMPLS_ip.mn
new file mode 100644
index 00000000..2634e788
--- /dev/null
+++ b/tests/mininet/l2/mpls/PushMPLS_ip.mn
@@ -0,0 +1,6 @@
+TEST_NAME=IP-PushMPLS
+DUMP_HOST=h2
+DUMP_IF=h2-eth0
+RYU_APP=test_mpls
+PCAP_MZ="-t tcp -P $TEST_NAME -c 3 -b 00:00:00:00:00:02"
+PCAP_FILTER="mpls && ip.proto==TCP"
diff --git a/tests/mininet/l2/mpls/PushMPLS_mpls.mn b/tests/mininet/l2/mpls/PushMPLS_mpls.mn
new file mode 100644
index 00000000..5ac1702f
--- /dev/null
+++ b/tests/mininet/l2/mpls/PushMPLS_mpls.mn
@@ -0,0 +1,6 @@
+TEST_NAME=MPLS-PushMPLS
+DUMP_HOST=h2
+DUMP_IF=h2-eth0
+RYU_APP=test_mpls
+PCAP_MZ="-t tcp -M 100 -P $TEST_NAME -c 3 -r"
+PCAP_FILTER="mpls.label==100 && mpls.label==200 && ip.proto==TCP"
diff --git a/tests/mininet/l2/mpls/test_mpls.py b/tests/mininet/l2/mpls/test_mpls.py
new file mode 100644
index 00000000..3090a08c
--- /dev/null
+++ b/tests/mininet/l2/mpls/test_mpls.py
@@ -0,0 +1,127 @@
+# Copyright (C) 2012 Nippon Telegraph and Telephone Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+import struct
+
+from ryu.base import app_manager
+from ryu.controller import ofp_event
+from ryu.controller import dpset
+from ryu.controller.handler import MAIN_DISPATCHER
+from ryu.controller.handler import set_ev_cls
+from ryu.ofproto import ofproto_v1_2
+from ryu.ofproto import ether
+from ryu.lib.mac import haddr_to_str
+
+
+LOG = logging.getLogger(__name__)
+
+
+class RunTestMininet(app_manager.RyuApp):
+
+ _CONTEXTS = {'dpset': dpset.DPSet}
+ OFP_VERSIONS = [ofproto_v1_2.OFP_VERSION]
+
+ def __init__(self, *args, **kwargs):
+ super(RunTestMininet, self).__init__(*args, **kwargs)
+
+ def _add_flow(self, dp, match, actions):
+ inst = [dp.ofproto_parser.OFPInstructionActions(
+ dp.ofproto.OFPIT_APPLY_ACTIONS, actions)]
+
+ mod = dp.ofproto_parser.OFPFlowMod(
+ dp, cookie=0, cookie_mask=0, table_id=0,
+ command=dp.ofproto.OFPFC_ADD, idle_timeout=0, hard_timeout=0,
+ priority=0xff, buffer_id=0xffffffff,
+ out_port=dp.ofproto.OFPP_ANY, out_group=dp.ofproto.OFPG_ANY,
+ flags=0, match=match, instructions=inst)
+
+ dp.send_msg(mod)
+
+ def _define_flow(self, dp):
+ in_port = 1
+ out_port = 2
+
+ eth_IP = ether.ETH_TYPE_IP
+ eth_MPLS = ether.ETH_TYPE_MPLS
+
+ # MPLS(80) -> PopMPLS
+ LOG.debug("--- add_flow PopMPLS")
+ m_label = 80
+ match = dp.ofproto_parser.OFPMatch()
+ match.set_in_port(in_port)
+ match.set_dl_type(eth_MPLS)
+ match.set_mpls_label(m_label)
+ actions = [dp.ofproto_parser.OFPActionPopMpls(eth_IP),
+ dp.ofproto_parser.OFPActionOutput(out_port, 0)]
+ self._add_flow(dp, match, actions)
+
+ # IP -> PushMPLS(90)
+ LOG.debug("--- add_flow PushMPLS")
+ s_label = 90
+ match = dp.ofproto_parser.OFPMatch()
+ match.set_in_port(in_port)
+ match.set_dl_type(eth_IP)
+ f = dp.ofproto_parser.OFPMatchField.make(
+ dp.ofproto.OXM_OF_MPLS_LABEL, s_label)
+ actions = [dp.ofproto_parser.OFPActionPushMpls(eth_MPLS),
+ dp.ofproto_parser.OFPActionSetField(f),
+ dp.ofproto_parser.OFPActionOutput(out_port, 0)]
+ self._add_flow(dp, match, actions)
+
+ # MPLS(100) -> PushMPLS(200)
+ LOG.debug("--- add_flow PushMPLS")
+ m_label = 100
+ s_label = 200
+ match = dp.ofproto_parser.OFPMatch()
+ match.set_in_port(in_port)
+ match.set_dl_type(eth_MPLS)
+ match.set_mpls_label(m_label)
+ f = dp.ofproto_parser.OFPMatchField.make(
+ dp.ofproto.OXM_OF_MPLS_LABEL, s_label)
+ actions = [dp.ofproto_parser.OFPActionPushMpls(eth_MPLS),
+ dp.ofproto_parser.OFPActionSetField(f),
+ dp.ofproto_parser.OFPActionOutput(out_port, 0)]
+ self._add_flow(dp, match, actions)
+
+ # MPLS(1000):MPLS -> PopMPLS
+ # LOG.debug("--- add_flow PopMPLS")
+ # SKIP: ovs not supported
+ m_label = 1000
+ match = dp.ofproto_parser.OFPMatch()
+ match.set_in_port(in_port)
+ match.set_dl_type(eth_MPLS)
+ match.set_mpls_label(m_label)
+ actions = [dp.ofproto_parser.OFPActionPopMpls(eth_MPLS),
+ dp.ofproto_parser.OFPActionOutput(out_port, 0)]
+ # self._add_flow(dp, match, actions)
+
+ @set_ev_cls(dpset.EventDP, dpset.DPSET_EV_DISPATCHER)
+ def handler_datapath(self, ev):
+ if ev.enter:
+ self._define_flow(ev.dp)
+
+ @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
+ def packet_in_handler(self, ev):
+ msg = ev.msg
+ dst, src, eth_type = struct.unpack_from('!6s6sH', buffer(msg.data), 0)
+ in_port = msg.match.fields[0].value
+
+ LOG.info("----------------------------------------")
+ LOG.info("* PacketIn")
+ LOG.info("in_port=%d, eth_type: %s", in_port, hex(eth_type))
+ LOG.info("packet reason=%d buffer_id=%d", msg.reason, msg.buffer_id)
+ LOG.info("packet in datapath_id=%s src=%s dst=%s",
+ msg.datapath.id, haddr_to_str(src), haddr_to_str(dst))
diff --git a/tests/mininet/l2/vlan/PopVLAN_vlan.mn b/tests/mininet/l2/vlan/PopVLAN_vlan.mn
new file mode 100644
index 00000000..f1d1c6dd
--- /dev/null
+++ b/tests/mininet/l2/vlan/PopVLAN_vlan.mn
@@ -0,0 +1,6 @@
+TEST_NAME=VLAN-PopVLAN
+DUMP_HOST=h2
+DUMP_IF=h2-eth0
+RYU_APP=test_vlan
+PCAP_MZ="-t tcp -Q 8 -P $TEST_NAME -c 3 -r"
+PCAP_FILTER="! vlan && ip.proto==TCP"
diff --git a/tests/mininet/l2/vlan/PopVLAN_vlanvlan.mn b/tests/mininet/l2/vlan/PopVLAN_vlanvlan.mn
new file mode 100644
index 00000000..90444a75
--- /dev/null
+++ b/tests/mininet/l2/vlan/PopVLAN_vlanvlan.mn
@@ -0,0 +1,6 @@
+TEST_NAME=VLAN:VLAN-PopVLAN
+DUMP_HOST=h2
+DUMP_IF=h2-eth0
+RYU_APP=test_vlan
+PCAP_MZ="-t tcp -Q 100,99 -P $TEST_NAME -c 3 -r"
+PCAP_FILTER="vlan.id!=100 && vlan.id==99 && ip.proto==TCP"
diff --git a/tests/mininet/l2/vlan/PushVLAN_icmp.mn b/tests/mininet/l2/vlan/PushVLAN_icmp.mn
new file mode 100644
index 00000000..439ad233
--- /dev/null
+++ b/tests/mininet/l2/vlan/PushVLAN_icmp.mn
@@ -0,0 +1,6 @@
+TEST_NAME=ICMP-PushVLAN
+DUMP_HOST=h2
+DUMP_IF=h2-eth0
+RYU_APP=test_vlan
+PCAP_MZ="-t icmp ping -P $TEST_NAME -c 3 -r -b 00:00:00:00:00:02"
+PCAP_FILTER="vlan && icmp.type==8"
diff --git a/tests/mininet/l2/vlan/test_vlan.py b/tests/mininet/l2/vlan/test_vlan.py
new file mode 100644
index 00000000..0b1be7fc
--- /dev/null
+++ b/tests/mininet/l2/vlan/test_vlan.py
@@ -0,0 +1,130 @@
+# Copyright (C) 2012 Nippon Telegraph and Telephone Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+import struct
+
+from ryu.base import app_manager
+from ryu.controller import ofp_event
+from ryu.controller import dpset
+from ryu.controller.handler import MAIN_DISPATCHER
+from ryu.controller.handler import set_ev_cls
+from ryu.ofproto import ofproto_v1_2
+from ryu.ofproto import ether
+from ryu.ofproto import inet
+from ryu.lib.mac import haddr_to_str
+
+
+LOG = logging.getLogger(__name__)
+
+
+class RunTestMininet(app_manager.RyuApp):
+
+ _CONTEXTS = {'dpset': dpset.DPSet}
+ OFP_VERSIONS = [ofproto_v1_2.OFP_VERSION]
+
+ def __init__(self, *args, **kwargs):
+ super(RunTestMininet, self).__init__(*args, **kwargs)
+
+ def _add_flow(self, dp, match, actions):
+ inst = [dp.ofproto_parser.OFPInstructionActions(
+ dp.ofproto.OFPIT_APPLY_ACTIONS, actions)]
+
+ mod = dp.ofproto_parser.OFPFlowMod(
+ dp, cookie=0, cookie_mask=0, table_id=0,
+ command=dp.ofproto.OFPFC_ADD, idle_timeout=0, hard_timeout=0,
+ priority=0xff, buffer_id=0xffffffff,
+ out_port=dp.ofproto.OFPP_ANY, out_group=dp.ofproto.OFPG_ANY,
+ flags=0, match=match, instructions=inst)
+
+ dp.send_msg(mod)
+
+ def _define_flow(self, dp):
+ in_port = 1
+ out_port = 2
+
+ eth_IP = ether.ETH_TYPE_IP
+ eth_VLAN = ether.ETH_TYPE_8021Q
+ ip_ICMP = inet.IPPROTO_ICMP
+
+ # VLAN(8) -> PopVLAN
+ LOG.debug("--- add_flow VLAN(8) to PopVLAN")
+ m_vid = 8
+ match = dp.ofproto_parser.OFPMatch()
+ match.set_in_port(in_port)
+ match.set_dl_type(eth_IP)
+ match.set_vlan_vid(m_vid)
+ actions = [dp.ofproto_parser.OFPActionPopVlan(),
+ dp.ofproto_parser.OFPActionOutput(out_port, 0)]
+ self._add_flow(dp, match, actions)
+
+ # ICMP -> PushVLAN(9)
+ LOG.debug("--- add_flow ICMP to PushVLAN(9)")
+ s_vid = 9
+ match = dp.ofproto_parser.OFPMatch()
+ match.set_in_port(in_port)
+ match.set_dl_type(eth_IP)
+ match.set_ip_proto(ip_ICMP)
+ f = dp.ofproto_parser.OFPMatchField.make(
+ dp.ofproto.OXM_OF_VLAN_VID, s_vid)
+ actions = [dp.ofproto_parser.OFPActionPushVlan(eth_VLAN),
+ dp.ofproto_parser.OFPActionSetField(f),
+ dp.ofproto_parser.OFPActionOutput(out_port, 0)]
+ self._add_flow(dp, match, actions)
+
+ # VLAN(10) -> PushVLAN(20)
+ # LOG.debug("--- add_flow VLAN(10) to PushVLAN(100)")
+ # SKIP: ovs not supported
+ m_vid = 10
+ s_vid = 20
+ match = dp.ofproto_parser.OFPMatch()
+ match.set_in_port(in_port)
+ match.set_dl_type(eth_IP)
+ match.set_vlan_vid(m_vid)
+ f = dp.ofproto_parser.OFPMatchField.make(
+ dp.ofproto.OXM_OF_VLAN_VID, s_vid)
+ actions = [dp.ofproto_parser.OFPActionPushVlan(eth_VLAN),
+ dp.ofproto_parser.OFPActionSetField(f),
+ dp.ofproto_parser.OFPActionOutput(out_port, 0)]
+ # self._add_flow(dp, match, actions)
+
+ # VLAN(100):VLAN -> PopVLAN
+ LOG.debug("--- add_flow VLAN(100):VLAN to PopVLAN")
+ m_vid = 100
+ match = dp.ofproto_parser.OFPMatch()
+ match.set_in_port(in_port)
+ match.set_dl_type(eth_VLAN)
+ match.set_vlan_vid(m_vid)
+ actions = [dp.ofproto_parser.OFPActionPopVlan(),
+ dp.ofproto_parser.OFPActionOutput(out_port, 0)]
+ self._add_flow(dp, match, actions)
+
+ @set_ev_cls(dpset.EventDP, dpset.DPSET_EV_DISPATCHER)
+ def handler_datapath(self, ev):
+ if ev.enter:
+ self._define_flow(ev.dp)
+
+ @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
+ def packet_in_handler(self, ev):
+ msg = ev.msg
+ dst, src, eth_type = struct.unpack_from('!6s6sH', buffer(msg.data), 0)
+ in_port = msg.match.fields[0].value
+
+ LOG.info("----------------------------------------")
+ LOG.info("* PacketIn")
+ LOG.info("in_port=%d, eth_type: %s", in_port, hex(eth_type))
+ LOG.info("packet reason=%d buffer_id=%d", msg.reason, msg.buffer_id)
+ LOG.info("packet in datapath_id=%s src=%s dst=%s",
+ msg.datapath.id, haddr_to_str(src), haddr_to_str(dst))