2016-07-12 14:51 GMT+02:00 Jiri Pirko <jiri@resnulli.us>:
Tue, Jul 12, 2016 at 11:00:30AM CEST, jprochaz@redhat.com wrote:
>Signed-off-by: Jiri Prochazka <jprochaz@redhat.com>
>---
> pyrecipes/3_vlans.py    | 34 ++++++++++++++++++++++++++++++++++
> pyrecipes/example.py    | 33 +++++++++++++++++++++++++++++++++
> pyrecipes/ping_flood.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 115 insertions(+)
> create mode 100644 pyrecipes/3_vlans.py
> create mode 100644 pyrecipes/example.py
> create mode 100644 pyrecipes/ping_flood.py
>
>diff --git a/pyrecipes/3_vlans.py b/pyrecipes/3_vlans.py
>new file mode 100644
>index 0000000..067fd33
>--- /dev/null
>+++ b/pyrecipes/3_vlans.py
>@@ -0,0 +1,34 @@
>+import lnst
>+
>+def ping_mod_init(if1, if2):
>+    ping_mod = lnst.get_module("IcmpPing",
>+                               options={
>+                                  "addr": if2.get_ip(0),
>+                                  "count": 10,
>+                                  "interval": 1,
>+                                  "iface" : if1.get_devname()})
>+    return ping_mod
>+
>+m1 = lnst.add_host()
>+m2 = lnst.add_host()
>+
>+m1_eth1 = m1.add_interface(label="tnet")
>+m2_eth1 = m2.add_interface(label="tnet")

This is misleading. Reader might think what you are actually creating
interfaces.

How about to have lnstMatchTemplate object, somethign like:

mt = lnstMatchTemplate()
h1 = mt.req_host()
h2 = mt.req_host()
...

while lnst.match(mt)


Looks much cleaner and "lnst" object might be actually re-used for more
match templates.



​Let this be one of the topics for the discussion with rest of the team in August​.
 

>+
>+while lnst.match():
>+    m1.sync_resources(modules=["IcmpPing"])
>+    m2.sync_resources(modules=["IcmpPing"])
>+
>+    m1_vlan10 = m1.create_vlan(realdev_iface=m1_eth1, vlan_tci="10", ip="192.168.10.1/24")
>+    m1_vlan20 = m1.create_vlan(realdev_iface=m1_eth1, vlan_tci="20", ip="192.168.20.1/24")
>+    m1_vlan30 = m1.create_vlan(realdev_iface=m1_eth1, vlan_tci="30", ip="192.168.30.1/24")
>+
>+    m2_vlan10 = m2.create_vlan(realdev_iface=m2_eth1, vlan_tci="10", ip="192.168.10.2/24")
>+    m2_vlan20 = m2.create_vlan(realdev_iface=m2_eth1, vlan_tci="20", ip="192.168.20.2/24")
>+    m2_vlan30 = m2.create_vlan(realdev_iface=m2_eth1, vlan_tci="30", ip="192.168.30.2/24")
>+
>+    ping_mod = ping_mod_init(m1_vlan10, m2_vlan10)
>+    ping_mod_bad = ping_mod_init(m1_vlan10, m2_vlan20)
>+
>+    m1.run(ping_mod)
>+    #m1.run(ping_mod_bad)
>diff --git a/pyrecipes/example.py b/pyrecipes/example.py
>new file mode 100644
>index 0000000..32c1b08
>--- /dev/null
>+++ b/pyrecipes/example.py
>@@ -0,0 +1,33 @@
>+import lnst
>+
>+# if1 ... src
>+# if2 ... dst
>+def ping_mod_init(if1, if2):
>+    ping_mod = lnst.get_module("IcmpPing",
>+                               options={
>+                                  "addr": if2.get_ip(0),
>+                                  "count": 10,
>+                                  "interval": 1,
>+                                  "iface" : if1.get_devname()})
>+    return ping_mod
>+
>+m1 = lnst.add_host()
>+m2 = lnst.add_host()
>+
>+m1_eth1 = m1.add_interface(label="tnet")
>+m1_eth2 = m1.add_interface(label="tnet")
>+m2_eth1 = m2.add_interface(label="tnet")
>+
>+while lnst.match():
>+    m1.sync_resources(modules=["IcmpPing"])
>+    m2.sync_resources(modules=["IcmpPing"])
>+    m2_eth1.reset(ip="192.168.0.2/24")
>+    ping = ping_mod_init(m1_eth1, m2_eth1)
>+    #lnst.breakpoint()
>+    team_if = m1.create_team(slaves=[m1_eth1, m1_eth2])
>+    #lnst.breakpoint()
>+    team_if.reset(ip="192.168.0.1/24")
>+    #lnst.breakpoint()
>+    ping = ping_mod_init(team_if, m2_eth1)
>+    #lnst.breakpoint()
>+    m1.run(ping)
>diff --git a/pyrecipes/ping_flood.py b/pyrecipes/ping_flood.py
>new file mode 100644
>index 0000000..e65879d
>--- /dev/null
>+++ b/pyrecipes/ping_flood.py
>@@ -0,0 +1,48 @@
>+import lnst
>+
>+m1 = lnst.add_host()
>+m2 = lnst.add_host()
>+
>+m1_eth1 = m1.add_interface(label="tnet")
>+m2_eth1 = m2.add_interface(label="tnet")
>+
>+while lnst.match():
>+    m1.sync_resources(modules=["Icmp6Ping", "IcmpPing"])
>+    m2.sync_resources(modules=["Icmp6Ping", "IcmpPing"])
>+
>+    lnst.wait(15)
>+
>+    ipv = lnst.get_alias("ipv", default="ipv4")
>+    print "ipv"
>+    print ipv
>+    mtu = lnst.get_alias("mtu", default="1500")
>+    print "mtu"
>+    print mtu
>+
>+    m1_eth1.reset(ip=["192.168.101.10/24", "fc00:0:0:0::1/64"])
>+    m2_eth1.reset(ip=["192.168.101.11/24", "fc00:0:0:0::2/64"])
>+
>+    ping_mod = lnst.get_module("IcmpPing",
>+                               options={
>+                                  "addr": m2_eth1.get_ip(0),
>+                                  "count": 10,
>+                                  "interval": 0.1,
>+                                  "iface" : m1_eth1.get_devname(),
>+                                  "limit_rate": 90})
>+
>+    ping_mod6 = lnst.get_module("Icmp6Ping",
>+                               options={
>+                                  "addr": m2_eth1.get_ip(1),
>+                                  "count": 10,
>+                                  "interval": 0.1,
>+                                  "iface" : m1_eth1.get_devname(),
>+                                  "limit_rate": 90})
>+
>+    m1_eth1.set_mtu(mtu)
>+    m2_eth1.set_mtu(mtu)
>+
>+    if ipv in [ 'ipv6', 'both' ]:
>+        m1.run(ping_mod6)
>+
>+    if ipv in ['ipv4', 'both' ]:
>+        m1.run(ping_mod)
>--
>2.4.11
>_______________________________________________
>LNST-developers mailing list
>lnst-developers@lists.fedorahosted.org
>https://lists.fedorahosted.org/admin/lists/lnst-developers@lists.fedorahosted.org