summaryrefslogtreecommitdiffhomepage
path: root/tests/mininet/l3
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-06-26 15:04:43 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-06-26 15:17:44 +0900
commita67ed2858417b9d795460f05126c01fb0cd344f9 (patch)
tree8171336c30668f8fce7d18125a591de86c322f40 /tests/mininet/l3
parentd8ae9491dab0824eb88b7e8aad044302d1463f84 (diff)
tests: Separate test files from Ryu module
To prevent redundant files (e.g., pcap files, json files for tests, packet data generator) to be installed, this patch separates test directory from Ryu module. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'tests/mininet/l3')
-rw-r--r--tests/mininet/l3/icmp/ICMP_ping.mn6
-rw-r--r--tests/mininet/l3/icmp/ICMP_reply.mn6
-rw-r--r--tests/mininet/l3/icmp/test_icmp.py84
-rw-r--r--tests/mininet/l3/ip_ttl/DecNwTtl.mn6
-rw-r--r--tests/mininet/l3/ip_ttl/test_ip_ttl.py84
5 files changed, 186 insertions, 0 deletions
diff --git a/tests/mininet/l3/icmp/ICMP_ping.mn b/tests/mininet/l3/icmp/ICMP_ping.mn
new file mode 100644
index 00000000..f558693d
--- /dev/null
+++ b/tests/mininet/l3/icmp/ICMP_ping.mn
@@ -0,0 +1,6 @@
+TEST_NAME=ICMP-Req
+DUMP_HOST=h2
+DUMP_IF=h2-eth0
+RYU_APP=test_icmp
+PCAP_MZ="-t icmp ping -c 3 -r -b 00:00:00:00:00:00"
+PCAP_FILTER="icmp.type==8"
diff --git a/tests/mininet/l3/icmp/ICMP_reply.mn b/tests/mininet/l3/icmp/ICMP_reply.mn
new file mode 100644
index 00000000..eb6bc8b6
--- /dev/null
+++ b/tests/mininet/l3/icmp/ICMP_reply.mn
@@ -0,0 +1,6 @@
+TEST_NAME=ICMP-Reply
+DUMP_HOST=h1
+DUMP_IF=h1-eth0
+RYU_APP=test_icmp
+PCAP_MZ="-t icmp ping -c 3 -r -B h2"
+PCAP_FILTER="icmp.type==0"
diff --git a/tests/mininet/l3/icmp/test_icmp.py b/tests/mininet/l3/icmp/test_icmp.py
new file mode 100644
index 00000000..090f83e5
--- /dev/null
+++ b/tests/mininet/l3/icmp/test_icmp.py
@@ -0,0 +1,84 @@
+# 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.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
+
+ # port:1 -> port:2
+ match = dp.ofproto_parser.OFPMatch()
+ match.set_in_port(in_port)
+ actions = [dp.ofproto_parser.OFPActionOutput(out_port, 0)]
+ self._add_flow(dp, match, actions)
+
+ # port:1 -> port:2
+ match = dp.ofproto_parser.OFPMatch()
+ match.set_in_port(out_port)
+ actions = [dp.ofproto_parser.OFPActionOutput(in_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/l3/ip_ttl/DecNwTtl.mn b/tests/mininet/l3/ip_ttl/DecNwTtl.mn
new file mode 100644
index 00000000..60cd4623
--- /dev/null
+++ b/tests/mininet/l3/ip_ttl/DecNwTtl.mn
@@ -0,0 +1,6 @@
+TEST_NAME=DecNwTtl
+DUMP_HOST=h2
+DUMP_IF=h2-eth0
+RYU_APP=test_ip_ttl
+PCAP_MZ="-t icmp ttl=64 -P $TEST_NAME -c 3 -b 00:00:00:00:00:02"
+PCAP_FILTER="icmp && ip.ttl==63"
diff --git a/tests/mininet/l3/ip_ttl/test_ip_ttl.py b/tests/mininet/l3/ip_ttl/test_ip_ttl.py
new file mode 100644
index 00000000..f6f00ab9
--- /dev/null
+++ b/tests/mininet/l3/ip_ttl/test_ip_ttl.py
@@ -0,0 +1,84 @@
+# 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
+
+ # ICMP -> DecNwTtl
+ LOG.debug("--- add_flow DecNwTtl")
+ match = dp.ofproto_parser.OFPMatch()
+ match.set_in_port(in_port)
+ match.set_dl_type(eth_IP)
+ actions = [dp.ofproto_parser.OFPActionDecNwTtl(),
+ 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))