Thanks for reply here is what I get: (I've attached netgraph.py and sp.py
which does shortest path routing)

sudo mn --mac --switch ovsk --custom ~/mininet/custom/netgraph.py --topo
mytopo --controller remote
ryu-manager ryu.app.sp ryu.app.rest_qos ryu.app.rest_conf_switch
ryu.app.rest_topology --observe-links

mininet> sh ovs-ofctl dump-flows s1
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=112.416s, table=0, n_packets=108, n_bytes=5508,
idle_age=0, priority=65535,dl_dst=01:80:c2:00:00:0e,dl_type=0x88cc
actions=CONTROLLER:51

http://127.0.0.1:8080/v1.0/topology/links

[{"src": {"hw_addr": "56:39:af:07:fb:3e", "name": "s3-eth2", "port_no":
"00000002", "dpid": "0000000000000003"}, "dst": {"hw_addr":
"ee:7c:7d:0d:55:a3", "name": "s4-eth1", "port_no": "00000001", "dpid":
"0000000000000004"}}, {"src": {"hw_addr": "d6:84:c4:43:12:00", "name":
"s4-eth4", "port_no": "00000004", "dpid": "0000000000000004"}, "dst":
{"hw_addr": "d2:f9:51:1e:78:a2", "name": "s2-eth2", "port_no": "00000002",
"dpid": "0000000000000002"}}, {"src": {"hw_addr": "d2:80:a1:e8:35:27",
"name": "s1-eth2", "port_no": "00000002", "dpid": "0000000000000001"},
"dst": {"hw_addr": "02:2e:17:a1:38:66", "name": "s2-eth1", "port_no":
"00000001", "dpid": "0000000000000002"}}, {"src": {"hw_addr":
"62:41:0f:84:fb:4d", "name": "s2-eth3", "port_no": "00000003", "dpid":
"0000000000000002"}, "dst": {"hw_addr": "d6:fc:b2:60:7c:60", "name":
"s5-eth3", "port_no": "00000003", "dpid": "0000000000000005"}}, {"src":
{"hw_addr": "d6:9a:51:9e:54:e4", "name": "s4-eth3", "port_no": "00000003",
"dpid": "0000000000000004"}, "dst": {"hw_addr": "7a:8c:8a:75:72:d8",
"name": "s6-eth2", "port_no": "00000002", "dpid": "0000000000000006"}},
{"src": {"hw_addr": "ee:7c:7d:0d:55:a3", "name": "s4-eth1", "port_no":
"00000001", "dpid": "0000000000000004"}, "dst": {"hw_addr":
"56:39:af:07:fb:3e", "name": "s3-eth2", "port_no": "00000002", "dpid":
"0000000000000003"}}, {"src": {"hw_addr": "02:2e:17:a1:38:66", "name":
"s2-eth1", "port_no": "00000001", "dpid": "0000000000000002"}, "dst":
{"hw_addr": "d2:80:a1:e8:35:27", "name": "s1-eth2", "port_no": "00000002",
"dpid": "0000000000000001"}}, {"src": {"hw_addr": "7a:8c:8a:75:72:d8",
"name": "s6-eth2", "port_no": "00000002", "dpid": "0000000000000006"},
"dst": {"hw_addr": "d6:9a:51:9e:54:e4", "name": "s4-eth3", "port_no":
"00000003", "dpid": "0000000000000004"}}, {"src": {"hw_addr":
"d2:f9:51:1e:78:a2", "name": "s2-eth2", "port_no": "00000002", "dpid":
"0000000000000002"}, "dst": {"hw_addr": "d6:84:c4:43:12:00", "name":
"s4-eth4", "port_no": "00000004", "dpid": "0000000000000004"}}, {"src":
{"hw_addr": "d6:fc:b2:60:7c:60", "name": "s5-eth3", "port_no": "00000003",
"dpid": "0000000000000005"}, "dst": {"hw_addr": "62:41:0f:84:fb:4d",
"name": "s2-eth3", "port_no": "00000003", "dpid": "0000000000000002"}},
{"src": {"hw_addr": "2a:c2:f4:09:e0:6d", "name": "s5-eth2", "port_no":
"00000002", "dpid": "0000000000000005"}, "dst": {"hw_addr":
"e2:6b:84:cc:08:70", "name": "s4-eth2", "port_no": "00000002", "dpid":
"0000000000000004"}}, {"src": {"hw_addr": "e2:6b:84:cc:08:70", "name":
"s4-eth2", "port_no": "00000002", "dpid": "0000000000000004"}, "dst":
{"hw_addr": "2a:c2:f4:09:e0:6d", "name": "s5-eth2", "port_no": "00000002",
"dpid": "0000000000000005"}}]

mininet> h1 ping h3
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
64 bytes from 10.0.0.3: icmp_seq=1 ttl=64 time=285 ms
64 bytes from 10.0.0.3: icmp_seq=2 ttl=64 time=0.128 ms
64 bytes from 10.0.0.3: icmp_seq=3 ttl=64 time=0.043 ms
^C
--- 10.0.0.3 ping statistics ---

http://127.0.0.1:8080/v1.0/topology/links
[{"src": {"hw_addr": "d2:f9:51:1e:78:a2", "name": "s2-eth2", "port_no":
"00000002", "dpid": "0000000000000002"}, "dst": {"hw_addr":
"7a:8c:8a:75:72:d8", "name": "s6-eth2", "port_no": "00000002", "dpid":
"0000000000000006"}}, {"src": {"hw_addr": "62:41:0f:84:fb:4d", "name":
"s2-eth3", "port_no": "00000003", "dpid": "0000000000000002"}, "dst":
{"hw_addr": "e2:6b:84:cc:08:70", "name": "s4-eth2", "port_no": "00000002",
"dpid": "0000000000000004"}}, {"src": {"hw_addr": "56:39:af:07:fb:3e",
"name": "s3-eth2", "port_no": "00000002", "dpid": "0000000000000003"},
"dst": {"hw_addr": "ee:7c:7d:0d:55:a3", "name": "s4-eth1", "port_no":
"00000001", "dpid": "0000000000000004"}}, {"src": {"hw_addr":
"7a:8c:8a:75:72:d8", "name": "s6-eth2", "port_no": "00000002", "dpid":
"0000000000000006"}, "dst": {"hw_addr": "62:41:0f:84:fb:4d", "name":
"s2-eth3", "port_no": "00000003", "dpid": "0000000000000002"}}, {"src":
{"hw_addr": "d6:84:c4:43:12:00", "name": "s4-eth4", "port_no": "00000004",
"dpid": "0000000000000004"}, "dst": {"hw_addr": "d6:fc:b2:60:7c:60",
"name": "s5-eth3", "port_no": "00000003", "dpid": "0000000000000005"}},
{"src": {"hw_addr": "d2:f9:51:1e:78:a2", "name": "s2-eth2", "port_no":
"00000002", "dpid": "0000000000000002"}, "dst": {"hw_addr":
"56:39:af:07:fb:3e", "name": "s3-eth2", "port_no": "00000002", "dpid":
"0000000000000003"}}, {"src": {"hw_addr": "d6:84:c4:43:12:00", "name":
"s4-eth4", "port_no": "00000004", "dpid": "0000000000000004"}, "dst":
{"hw_addr": "d2:f9:51:1e:78:a2", "name": "s2-eth2", "port_no": "00000002",
"dpid": "0000000000000002"}}, {"src": {"hw_addr": "7a:8c:8a:75:72:d8",
"name": "s6-eth2", "port_no": "00000002", "dpid": "0000000000000006"},
"dst": {"hw_addr": "56:39:af:07:fb:3e", "name": "s3-eth2", "port_no":
"00000002", "dpid": "0000000000000003"}}, {"src": {"hw_addr":
"d6:84:c4:43:12:00", "name": "s4-eth4", "port_no": "00000004", "dpid":
"0000000000000004"}, "dst": {"hw_addr": "d2:80:a1:e8:35:27", "name":
"s1-eth2", "port_no": "00000002", "dpid": "0000000000000001"}}, {"src":
{"hw_addr": "7a:8c:8a:75:72:d8", "name": "s6-eth2", "port_no": "00000002",
"dpid": "0000000000000006"}, "dst": {"hw_addr": "d2:f9:51:1e:78:a2",
"name": "s2-eth2", "port_no": "00000002", "dpid": "0000000000000002"}},
{"src": {"hw_addr": "2a:c2:f4:09:e0:6d", "name": "s5-eth2", "port_no":
"00000002", "dpid": "0000000000000005"}, "dst": {"hw_addr":
"e2:6b:84:cc:08:70", "name": "s4-eth2", "port_no": "00000002", "dpid":
"0000000000000004"}}, {"src": {"hw_addr": "56:39:af:07:fb:3e", "name":
"s3-eth2", "port_no": "00000002", "dpid": "0000000000000003"}, "dst":
{"hw_addr": "2a:c2:f4:09:e0:6d", "name": "s5-eth2", "port_no": "00000002",
"dpid": "0000000000000005"}}, {"src": {"hw_addr": "7a:8c:8a:75:72:d8",
"name": "s6-eth2", "port_no": "00000002", "dpid": "0000000000000006"},
"dst": {"hw_addr": "2a:c2:f4:09:e0:6d", "name": "s5-eth2", "port_no":
"00000002", "dpid": "0000000000000005"}}, {"src": {"hw_addr":
"d2:f9:51:1e:78:a2", "name": "s2-eth2", "port_no": "00000002", "dpid":
"0000000000000002"}, "dst": {"hw_addr": "2a:c2:f4:09:e0:6d", "name":
"s5-eth2", "port_no": "00000002", "dpid": "0000000000000005"}}, {"src":
{"hw_addr": "d2:80:a1:e8:35:27", "name": "s1-eth2", "port_no": "00000002",
"dpid": "0000000000000001"}, "dst": {"hw_addr": "02:2e:17:a1:38:66",
"name": "s2-eth1", "port_no": "00000001", "dpid": "0000000000000002"}},
{"src": {"hw_addr": "2a:c2:f4:09:e0:6d", "name": "s5-eth2", "port_no":
"00000002", "dpid": "0000000000000005"}, "dst": {"hw_addr":
"d2:f9:51:1e:78:a2", "name": "s2-eth2", "port_no": "00000002", "dpid":
"0000000000000002"}}, {"src": {"hw_addr": "e2:6b:84:cc:08:70", "name":
"s4-eth2", "port_no": "00000002", "dpid": "0000000000000004"}, "dst":
{"hw_addr": "56:39:af:07:fb:3e", "name": "s3-eth2", "port_no": "00000002",
"dpid": "0000000000000003"}}, {"src": {"hw_addr": "d2:f9:51:1e:78:a2",
"name": "s2-eth2", "port_no": "00000002", "dpid": "0000000000000002"},
"dst": {"hw_addr": "d2:80:a1:e8:35:27", "name": "s1-eth2", "port_no":
"00000002", "dpid": "0000000000000001"}}, {"src": {"hw_addr":
"d6:84:c4:43:12:00", "name": "s4-eth4", "port_no": "00000004", "dpid":
"0000000000000004"}, "dst": {"hw_addr": "7a:8c:8a:75:72:d8", "name":
"s6-eth2", "port_no": "00000002", "dpid": "0000000000000006"}}, {"src":
{"hw_addr": "e2:6b:84:cc:08:70", "name": "s4-eth2", "port_no": "00000002",
"dpid": "0000000000000004"}, "dst": {"hw_addr": "2a:c2:f4:09:e0:6d",
"name": "s5-eth2", "port_no": "00000002", "dpid": "0000000000000005"}},
{"src": {"hw_addr": "7a:8c:8a:75:72:d8", "name": "s6-eth2", "port_no":
"00000002", "dpid": "0000000000000006"}, "dst": {"hw_addr":
"d6:9a:51:9e:54:e4", "name": "s4-eth3", "port_no": "00000003", "dpid":
"0000000000000004"}}, {"src": {"hw_addr": "56:39:af:07:fb:3e", "name":
"s3-eth2", "port_no": "00000002", "dpid": "0000000000000003"}, "dst":
{"hw_addr": "d6:fc:b2:60:7c:60", "name": "s5-eth3", "port_no": "00000003",
"dpid": "0000000000000005"}}, {"src": {"hw_addr": "62:41:0f:84:fb:4d",
"name": "s2-eth3", "port_no": "00000003", "dpid": "0000000000000002"},
"dst": {"hw_addr": "d6:fc:b2:60:7c:60", "name": "s5-eth3", "port_no":
"00000003", "dpid": "0000000000000005"}}, {"src": {"hw_addr":
"2a:c2:f4:09:e0:6d", "name": "s5-eth2", "port_no": "00000002", "dpid":
"0000000000000005"}, "dst": {"hw_addr": "d2:80:a1:e8:35:27", "name":
"s1-eth2", "port_no": "00000002", "dpid": "0000000000000001"}}, {"src":
{"hw_addr": "56:39:af:07:fb:3e", "name": "s3-eth2", "port_no": "00000002",
"dpid": "0000000000000003"}, "dst": {"hw_addr": "62:41:0f:84:fb:4d",
"name": "s2-eth3", "port_no": "00000003", "dpid": "0000000000000002"}},
{"src": {"hw_addr": "56:39:af:07:fb:3e", "name": "s3-eth2", "port_no":
"00000002", "dpid": "0000000000000003"}, "dst": {"hw_addr":
"d2:f9:51:1e:78:a2", "name": "s2-eth2", "port_no": "00000002", "dpid":
"0000000000000002"}}, {"src": {"hw_addr": "2a:c2:f4:09:e0:6d", "name":
"s5-eth2", "port_no": "00000002", "dpid": "0000000000000005"}, "dst":
{"hw_addr": "56:39:af:07:fb:3e", "name": "s3-eth2", "port_no": "00000002",
"dpid": "0000000000000003"}}, {"src": {"hw_addr": "e2:6b:84:cc:08:70",
"name": "s4-eth2", "port_no": "00000002", "dpid": "0000000000000004"},
"dst": {"hw_addr": "d2:80:a1:e8:35:27", "name": "s1-eth2", "port_no":
"00000002", "dpid": "0000000000000001"}}, {"src": {"hw_addr":
"d2:80:a1:e8:35:27", "name": "s1-eth2", "port_no": "00000002", "dpid":
"0000000000000001"}, "dst": {"hw_addr": "d6:fc:b2:60:7c:60", "name":
"s5-eth3", "port_no": "00000003", "dpid": "0000000000000005"}}, {"src":
{"hw_addr": "d6:fc:b2:60:7c:60", "name": "s5-eth3", "port_no": "00000003",
"dpid": "0000000000000005"}, "dst": {"hw_addr": "d2:80:a1:e8:35:27",
"name": "s1-eth2", "port_no": "00000002", "dpid": "0000000000000001"}},
{"src": {"hw_addr": "d6:fc:b2:60:7c:60", "name": "s5-eth3", "port_no":
"00000003", "dpid": "0000000000000005"}, "dst": {"hw_addr":
"d6:84:c4:43:12:00", "name": "s4-eth4", "port_no": "00000004", "dpid":
"0000000000000004"}}, {"src": {"hw_addr": "56:39:af:07:fb:3e", "name":
"s3-eth2", "port_no": "00000002", "dpid": "0000000000000003"}, "dst":
{"hw_addr": "7a:8c:8a:75:72:d8", "name": "s6-eth2", "port_no": "00000002",
"dpid": "0000000000000006"}}, {"src": {"hw_addr": "ee:7c:7d:0d:55:a3",
"name": "s4-eth1", "port_no": "00000001", "dpid": "0000000000000004"},
"dst": {"hw_addr": "56:39:af:07:fb:3e", "name": "s3-eth2", "port_no":
"00000002", "dpid": "0000000000000003"}}, {"src": {"hw_addr":
"d6:84:c4:43:12:00", "name": "s4-eth4", "port_no": "00000004", "dpid":
"0000000000000004"}, "dst": {"hw_addr": "56:39:af:07:fb:3e", "name":
"s3-eth2", "port_no": "00000002", "dpid": "0000000000000003"}}, {"src":
{"hw_addr": "e2:6b:84:cc:08:70", "name": "s4-eth2", "port_no": "00000002",
"dpid": "0000000000000004"}, "dst": {"hw_addr": "7a:8c:8a:75:72:d8",
"name": "s6-eth2", "port_no": "00000002", "dpid": "0000000000000006"}},
{"src": {"hw_addr": "d6:9a:51:9e:54:e4", "name": "s4-eth3", "port_no":
"00000003", "dpid": "0000000000000004"}, "dst": {"hw_addr":
"7a:8c:8a:75:72:d8", "name": "s6-eth2", "port_no": "00000002", "dpid":
"0000000000000006"}}, {"src": {"hw_addr": "d2:80:a1:e8:35:27", "name":
"s1-eth2", "port_no": "00000002", "dpid": "0000000000000001"}, "dst":
{"hw_addr": "d6:84:c4:43:12:00", "name": "s4-eth4", "port_no": "00000004",
"dpid": "0000000000000004"}}, {"src": {"hw_addr": "56:39:af:07:fb:3e",
"name": "s3-eth2", "port_no": "00000002", "dpid": "0000000000000003"},
"dst": {"hw_addr": "d2:80:a1:e8:35:27", "name": "s1-eth2", "port_no":
"00000002", "dpid": "0000000000000001"}}, {"src": {"hw_addr":
"02:2e:17:a1:38:66", "name": "s2-eth1", "port_no": "00000001", "dpid":
"0000000000000002"}, "dst": {"hw_addr": "d2:80:a1:e8:35:27", "name":
"s1-eth2", "port_no": "00000002", "dpid": "0000000000000001"}}, {"src":
{"hw_addr": "e2:6b:84:cc:08:70", "name": "s4-eth2", "port_no": "00000002",
"dpid": "0000000000000004"}, "dst": {"hw_addr": "62:41:0f:84:fb:4d",
"name": "s2-eth3", "port_no": "00000003", "dpid": "0000000000000002"}},
{"src": {"hw_addr": "d2:f9:51:1e:78:a2", "name": "s2-eth2", "port_no":
"00000002", "dpid": "0000000000000002"}, "dst": {"hw_addr":
"d6:84:c4:43:12:00", "name": "s4-eth4", "port_no": "00000004", "dpid":
"0000000000000004"}}, {"src": {"hw_addr": "d6:fc:b2:60:7c:60", "name":
"s5-eth3", "port_no": "00000003", "dpid": "0000000000000005"}, "dst":
{"hw_addr": "62:41:0f:84:fb:4d", "name": "s2-eth3", "port_no": "00000003",
"dpid": "0000000000000002"}}, {"src": {"hw_addr": "2a:c2:f4:09:e0:6d",
"name": "s5-eth2", "port_no": "00000002", "dpid": "0000000000000005"},
"dst": {"hw_addr": "7a:8c:8a:75:72:d8", "name": "s6-eth2", "port_no":
"00000002", "dpid": "0000000000000006"}}]


Thanks...


On Tue, Oct 20, 2015 at 9:53 AM, Yusuke Iwase <[email protected]>
wrote:

> Hi,
>
>
> On 2015年10月20日 06:49, Ezzat Zar wrote:
> > Hi again,
> > There seems to be another problem with rest_topology.py which I cannot
> figure out how to resolve. When I use
> >
> > GET /v1.0/topology/links
> >
> > at the beginning of network creation, it show links between switches
> correctly. But when I start sending packets through the network, using this
> shows up a whole bunch of new links which does not really exist in the
> topology... For example if a packet had been forwarded from a switch to
> another via multiple switch hops, a link shows up from source to
> destination switch!
>
> Could you show us the flow entries you installed?
> On my environment, rest_topology.py outputs all links correctly.
>
> $ sudo mn --topo linear,3 --mac --controller remote
>
> $ ryu-manager --observe-links ryu.app.rest_topology
> ryu.app.simple_switch_13
>
> Before ping:
> mininet> sh ovs-ofctl dump-flows s1
> NXST_FLOW reply (xid=0x4):
>  cookie=0x0, duration=16.729s, table=0, n_packets=18, n_bytes=918,
> idle_age=1, priority=65535,dl_dst=01:80:c2:00:00:0e,dl_type=0x88cc
> actions=CONTROLLER:65535
>  cookie=0x0, duration=16.730s, table=0, n_packets=64, n_bytes=8962,
> idle_age=6, priority=0 actions=CONTROLLER:65535
>
> $ curl -X GET http://localhost:8080/v1.0/topology/links
> [{"src": {"hw_addr": "66:df:c7:f7:0c:04", "name": "s2-eth3", "port_no":
> "00000003", "dpid": "0000000000000002"}, "dst": {"hw_addr":
> "16:3c:5a:66:aa:f6", "name": "s3-eth2", "port_no": "00000002", "dpid":
> "0000000000000003"}}, {"src": {"hw_addr": "4e:51:8c:48:4d:d8", "name":
> "s2-eth2", "port_no": "00000002", "dpid": "0000000000000002"}, "dst":
> {"hw_addr": "96:ae:dd:c4:0f:c0", "name": "s1-eth2", "port_no": "00000002",
> "dpid": "0000000000000001"}}, {"src": {"hw_addr": "16:3c:5a:66:aa:f6",
> "name": "s3-eth2", "port_no": "00000002", "dpid": "0000000000000003"},
> "dst": {"hw_addr": "66:df:c7:f7:0c:04", "name": "s2-eth3", "port_no":
> "00000003", "dpid": "0000000000000002"}}, {"src": {"hw_addr":
> "96:ae:dd:c4:0f:c0", "name": "s1-eth2", "port_no": "00000002", "dpid":
> "0000000000000001"}, "dst": {"hw_addr": "4e:51:8c:48:4d:d8", "name":
> "s2-eth2", "port_no": "00000002", "dpid": "0000000000000002"}}]
>
> mininet> h1 ping h3
> PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
> 64 bytes from 10.0.0.3: icmp_seq=1 ttl=64 time=21.6 ms
> 64 bytes from 10.0.0.3: icmp_seq=2 ttl=64 time=0.068 ms
>   ...
>
> After ping:
> mininet> sh ovs-ofctl dump-flows s1
> NXST_FLOW reply (xid=0x4):
>  cookie=0x0, duration=55.786s, table=0, n_packets=62, n_bytes=3162,
> idle_age=0, priority=65535,dl_dst=01:80:c2:00:00:0e,dl_type=0x88cc
> actions=CONTROLLER:65535
>  cookie=0x0, duration=4.954s, table=0, n_packets=4, n_bytes=336,
> idle_age=2, priority=1,in_port=2,dl_dst=00:00:00:00:00:01 actions=output:1
>  cookie=0x0, duration=4.950s, table=0, n_packets=3, n_bytes=294,
> idle_age=2, priority=1,in_port=1,dl_dst=00:00:00:00:00:03 actions=output:2
>  cookie=0x0, duration=55.787s, table=0, n_packets=71, n_bytes=9572,
> idle_age=4, priority=0 actions=CONTROLLER:65535
>
> $ curl -X GET http://localhost:8080/v1.0/topology/links
> [{"src": {"hw_addr": "66:df:c7:f7:0c:04", "name": "s2-eth3", "port_no":
> "00000003", "dpid": "0000000000000002"}, "dst": {"hw_addr":
> "16:3c:5a:66:aa:f6", "name": "s3-eth2", "port_no": "00000002", "dpid":
> "0000000000000003"}}, {"src": {"hw_addr": "4e:51:8c:48:4d:d8", "name":
> "s2-eth2", "port_no": "00000002", "dpid": "0000000000000002"}, "dst":
> {"hw_addr": "96:ae:dd:c4:0f:c0", "name": "s1-eth2", "port_no": "00000002",
> "dpid": "0000000000000001"}}, {"src": {"hw_addr": "16:3c:5a:66:aa:f6",
> "name": "s3-eth2", "port_no": "00000002", "dpid": "0000000000000003"},
> "dst": {"hw_addr": "66:df:c7:f7:0c:04", "name": "s2-eth3", "port_no":
> "00000003", "dpid": "0000000000000002"}}, {"src": {"hw_addr":
> "96:ae:dd:c4:0f:c0", "name": "s1-eth2", "port_no": "00000002", "dpid":
> "0000000000000001"}, "dst": {"hw_addr": "4e:51:8c:48:4d:d8", "name":
> "s2-eth2", "port_no": "00000002", "dpid": "0000000000000002"}}]
>
> Thanks,
> Iwase
>
> >
> > Any idea on how to resolve this issue?  I can use the topology from
> prior data transfer phase but I need to periodically access topology info
> during network runtime too.
> >
> > Thanks.
> >
> >
> >
> >
> ------------------------------------------------------------------------------
> >
> >
> >
> > _______________________________________________
> > Ryu-devel mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/ryu-devel
> >
>
"""Custom topology example

Two directly connected switches plus a host for each switch:

   host --- switch --- switch --- host

Adding the 'topos' dict with a key/value pair to generate our newly defined
topology enables one to pass in '--topo=mytopo' from the command line.
"""

from mininet.topo import Topo

class MyTopo( Topo ):
    "Simple topology example."

    def __init__( self ):
        "Create custom topo."

        # Initialize topology
        Topo.__init__( self )

        # Add hosts and switches
        h1 = self.addHost( 'h1' )
        h2 = self.addHost( 'h2' )
        h3 = self.addHost( 'h3' )
        h4 = self.addHost( 'h4' )
        s1 = self.addSwitch( 's1' )
        s2 = self.addSwitch( 's2' )
        s3 = self.addSwitch( 's3' )
        s4 = self.addSwitch( 's4' )
        s5 = self.addSwitch( 's5' )
        s6 = self.addSwitch( 's6' )

        # Add links
        self.addLink( s1, h3 )
        self.addLink( s3, h2 )
        self.addLink( s5, h4 )
        self.addLink( s6, h1 )
        self.addLink( s1, s2 )
        self.addLink( s3, s4 )
        self.addLink( s4, s5 )
        self.addLink( s4, s6 )
        self.addLink( s2, s4 )
        self.addLink( s2, s5 )

topos = { 'mytopo': ( lambda: MyTopo() ) }
#  This is part of our final project for the Computer Networks Graduate Course at Georgia Tech
#    You can take the official course online too! Just google CS 6250 online at Georgia Tech.
#
#  Contributors:
#   
#    Akshar Rawal ([email protected])
#    Flavio Castro ([email protected])
#    Logan Blyth ([email protected])
#    Matthew Hicks ([email protected])
#    Uy Nguyen ([email protected])
#
#  To run:
#    
#    ryu--manager --observe-links shortestpath.py   
#
#Copyright (C) 2014, Georgia Institute of Technology.
#
# 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.

"""
An OpenFlow 1.0 shortest path forwarding implementation.
"""

import logging
import struct

from ryu.base import app_manager
from ryu.controller import mac_to_port
from ryu.controller import ofp_event
from ryu.controller.handler import MAIN_DISPATCHER, CONFIG_DISPATCHER
from ryu.controller.handler import set_ev_cls
from ryu.ofproto import ofproto_v1_0
from ryu.lib.mac import haddr_to_bin
from ryu.lib.packet import packet
from ryu.lib.packet import ethernet

from ryu.topology.api import get_switch, get_link
from ryu.app.wsgi import ControllerBase
from ryu.topology import event, switches 
import networkx as nx

class ProjectController(app_manager.RyuApp):
	
    OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION]

    def __init__(self, *args, **kwargs):
        super(ProjectController, self).__init__(*args, **kwargs)
        self.mac_to_port = {}
        self.topology_api_app = self
        self.net=nx.DiGraph()
        self.nodes = {}
        self.links = {}
        self.no_of_nodes = 0
        self.no_of_links = 0
        self.i=0


    # Handy function that lists all attributes in the given object
    def ls(self,obj):
        print("\n".join([x for x in dir(obj) if x[0] != "_"]))
	
    def add_flow(self, datapath, in_port, dst, actions):
        ofproto = datapath.ofproto

        match = datapath.ofproto_parser.OFPMatch(
            in_port=in_port, dl_dst=haddr_to_bin(dst))

        mod = datapath.ofproto_parser.OFPFlowMod(
            datapath=datapath, match=match, cookie=0,
            command=ofproto.OFPFC_ADD, idle_timeout=0, hard_timeout=0,
            priority=ofproto.OFP_DEFAULT_PRIORITY,
            flags=ofproto.OFPFF_SEND_FLOW_REM, actions=actions)
        datapath.send_msg(mod)

    @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
    def _packet_in_handler(self, ev):
        msg = ev.msg
        datapath = msg.datapath
        ofproto = datapath.ofproto

        pkt = packet.Packet(msg.data)
        eth = pkt.get_protocol(ethernet.ethernet)

        dst = eth.dst
        src = eth.src
        dpid = datapath.id
        self.mac_to_port.setdefault(dpid, {})
        # print "nodes"
        # print self.net.nodes()
        # print "edges"
        # print len(self.net.edges())
        #self.logger.info("packet in %s %s %s %s", dpid, src, dst, msg.in_port)
        if src not in self.net:
            self.net.add_node(src)
            self.net.add_edge(dpid,src,{'port':msg.in_port})
            self.net.add_edge(src,dpid)
        if dst in self.net:
            #print (src in self.net)
            # print nx.shortest_path(self.net,1,5)
            # print nx.shortest_path(self.net,6,3)
            #print nx.shortest_path(self.net,src,4)

            path=nx.shortest_path(self.net,src,dst)   
            next=path[path.index(dpid)+1]
            out_port=self.net[dpid][next]['port']
        else:
            out_port = ofproto.OFPP_FLOOD

        actions = [datapath.ofproto_parser.OFPActionOutput(out_port)]

        # install a flow to avoid packet_in next time
        if out_port != ofproto.OFPP_FLOOD:
            self.add_flow(datapath, msg.in_port, dst, actions)

        out = datapath.ofproto_parser.OFPPacketOut(
            datapath=datapath, buffer_id=msg.buffer_id, in_port=msg.in_port,
            actions=actions)
        datapath.send_msg(out)
    @set_ev_cls(event.EventSwitchEnter)
    def get_topology_data(self, ev):
        switch_list = get_switch(self.topology_api_app, None)   
        switches=[switch.dp.id for switch in switch_list]
        self.net.add_nodes_from(switches)
         
        #print "**********List of switches"
        #for switch in switch_list:
        #self.ls(switch)
        #print switch
        #self.nodes[self.no_of_nodes] = switch
        #self.no_of_nodes += 1
        #self.logger.info('port.name=%s', switch.dp.ports[3].name)  # --> port.name=s1-eth1
        links_list = get_link(self.topology_api_app, None)
        #print links_list
        links=[(link.src.dpid,link.dst.dpid,{'port':link.src.port_no}) for link in links_list]
        #print links
        self.net.add_edges_from(links)
        links=[(link.dst.dpid,link.src.dpid,{'port':link.dst.port_no}) for link in links_list]
        #print links
        self.net.add_edges_from(links)

        print "**********List of links"
        print self.net.edges()

        # for link in links_list:
	    # print link.dst
         #    print link.src
         #    print "Novo link"
	    # self.no_of_links += 1
      
        
	#print "@@@@@@@@@@@@@@@@@Printing both arrays@@@@@@@@@@@@@@@"
    #for node in self.nodes:	
	#    print self.nodes[node]
	#for link in self.links:
	#    print self.links[link]
	#print self.no_of_nodes
	#print self.no_of_links

    #@set_ev_cls(event.EventLinkAdd)
    #def get_links(self, ev):
	#print "################Something##############"
	#print ev.link.src, ev.link.dst
------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to