Merge "Modified documents with new references for Be release"
[docs.git] / manuals / user-guide / src / main / asciidoc / vtn / VTN_How_To_Use_VTN_to_make_packets_take_different_paths.adoc
1 ==== How To Use VTN To Make Packets Take Different Paths
2 This example demonstrates on how to create a specific VTN Path Map information.
3
4 .PathMap
5 image::vtn/Pathmap.png["Pathmap" ,width= 500]
6
7 ===== Requirement
8 * Save the mininet script given below as pathmap_test.py and run the mininet script in the mininet environment where Mininet is installed.
9
10 * Create topology using the below mininet script:
11
12 ----
13  from mininet.topo import Topo
14  class MyTopo( Topo ):
15     "Simple topology example."
16     def __init__( self ):
17         "Create custom topo."
18         # Initialize topology
19         Topo.__init__( self )
20         # Add hosts and switches
21         leftHost = self.addHost( 'h1' )
22         rightHost = self.addHost( 'h2' )
23         leftSwitch = self.addSwitch( 's1' )
24         middleSwitch = self.addSwitch( 's2' )
25         middleSwitch2 = self.addSwitch( 's4' )
26         rightSwitch = self.addSwitch( 's3' )
27         # Add links
28         self.addLink( leftHost, leftSwitch )
29         self.addLink( leftSwitch, middleSwitch )
30         self.addLink( leftSwitch, middleSwitch2 )
31         self.addLink( middleSwitch, rightSwitch )
32         self.addLink( middleSwitch2, rightSwitch )
33         self.addLink( rightSwitch, rightHost )
34  topos = { 'mytopo': ( lambda: MyTopo() ) }
35 ----
36
37 ----
38  mininet> net
39  c0
40  s1 lo:  s1-eth1:h1-eth0 s1-eth2:s2-eth1 s1-eth3:s4-eth1
41  s2 lo:  s2-eth1:s1-eth2 s2-eth2:s3-eth1
42  s3 lo:  s3-eth1:s2-eth2 s3-eth2:s4-eth2 s3-eth3:h2-eth0
43  s4 lo:  s4-eth1:s1-eth3 s4-eth2:s3-eth2
44  h1 h1-eth0:s1-eth1
45  h2 h2-eth0:s3-eth3
46 ----
47
48 NOTE: Add the default flow to OVS to forward packets to controller when there is a table-miss:
49
50 ----
51 ovs-ofctl --protocols=OpenFlow13 add-flow <switch-name> priority=0,actions=output:CONTROLLER
52 ----
53
54 These flows need to be added only in case of OpenFlow1.3 or using OVS versions (>2.1.1).
55
56 Here the switch name is the switches in the topology such as s1,s2,s3.
57
58 * Generate traffic by pinging between hosts h1 and h2 before creating the portmaps respectively
59
60 ----
61   mininet> h1 ping h2
62   PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
63   From 10.0.0.1 icmp_seq=1 Destination Host Unreachable
64   From 10.0.0.1 icmp_seq=2 Destination Host Unreachable
65   From 10.0.0.1 icmp_seq=3 Destination Host Unreachable
66   From 10.0.0.1 icmp_seq=4 Destination Host Unreachable
67 ----
68
69 ===== Configuration
70 * Create Controller
71
72 ----
73 curl --user admin:adminpass -H 'content-type: application/json'  -X POST -d '{"controller": {"controller_id": "odc", "ipaddr":"10.100.9.42", "type": "odc", "version": "1.0", "auditstatus":"enable"}}' http://127.0.0.1:8083/vtn-webapi/controllers.json
74 ----
75
76 * Create a VTN
77
78 ----
79 curl --user admin:adminpass -H 'content-type: application/json'  -X POST -d '{"vtn" : {"vtn_name":"vtn1","description":"test VTN" }}' http://127.0.0.1:8083/vtn-webapi/vtns.json
80 ----
81
82 * Create a vBridge in the VTN
83
84 ----
85 curl --user admin:adminpass -H 'content-type: application/json'  -X POST -d '{"vbridge" : {"vbr_name":"vBridge1","controller_id":"odc","domain_id":"(DEFAULT)" }}' http://127.0.0.1:8083/vtn-webapi/vtns/vtn1/vbridges.json
86 ----
87
88 * Create two Interfaces into the vBridge
89
90 ----
91 curl --user admin:adminpass -H 'content-type: application/json'  -X POST -d '{"interface": {"if_name": "if1","description": "if_desc1"}}' http://127.0.0.1:8083/vtn-webapi/vtns/vtn1/vbridges/vBridge1/interfaces.json
92 curl --user admin:adminpass -H 'content-type: application/json'  -X POST -d '{"interface": {"if_name": "if2","description": "if_desc2"}}' http://127.0.0.1:8083/vtn-webapi/vtns/vtn1/vbridges/vBridge1/interfaces.json
93 ----
94
95 * Configure two mappings on the interfaces
96
97 ----
98 curl --user admin:adminpass -H 'content-type: application/json'  -X PUT -d '{"portmap":{"logical_port_id": "PP-OF:00:00:00:00:00:00:00:01-s1-eth1"}}' http://127.0.0.1:8083/vtn-webapi/vtns/vtn1/vbridges/vBridge1/interfaces/if1/portmap.json
99 curl --user admin:adminpass -H 'content-type: application/json'  -X PUT -d '{"portmap":{"logical_port_id": "PP-OF:00:00:00:00:00:00:00:03-s3-eth3"}}' http://127.0.0.1:8083/vtn-webapi/vtns/vtn1/vbridges/vBridge1/interfaces/if2/portmap.json
100 ----
101
102 * Generate traffic by pinging between hosts h1 and h2 after creating the portmaps respectively
103
104 ----
105   mininet> h1 ping h2
106   PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
107   64 bytes from 10.0.0.2: icmp_req=1 ttl=64 time=36.4 ms
108   64 bytes from 10.0.0.2: icmp_req=2 ttl=64 time=0.880 ms
109   64 bytes from 10.0.0.2: icmp_req=3 ttl=64 time=0.073 ms
110   64 bytes from 10.0.0.2: icmp_req=4 ttl=64 time=0.081 ms
111 ----
112
113 * Get the VTN Dataflows information
114
115 ----
116 curl -X GET -H 'content-type: application/json' --user 'admin:adminpass' "http://127.0.0.1:8083/vtn-webapi/dataflows?&switch_id=00:00:00:00:00:00:00:01&port_name=s1-eth1&controller_id=odc&srcmacaddr=de3d.7dec.e4d2&no_vlan_id=true"
117 ----
118
119 * Create a Flowcondition in the VTN
120
121 ----
122 curl --user "admin":"admin" -H "Content-type: application/json" -X POST http://localhost:8181/restconf/operations/vtn-flow-condition:set-flow-condition -d '{"input":{"operation":"SET","present":"false","name":"cond_1", "vtn-flow-match":[{"vtn-ether-match":{},"vtn-inet-match":{"source-network":"10.0.0.1/32","protocol":1,"destination-network":"10.0.0.2/32"},"index":"1"}]}}'
123 ----
124
125 * Create a Pathmap in the VTN
126
127 ----
128 curl --user "admin":"admin" -H "Content-type: application/json" -X POST http://localhost:8181/restconf/operations/vtn-path-map:set-path-map -d '{"input":{"tenant-name":"vtn1","path-map-list":[{"condition":"cond_1","policy":"1","index": "1","idle-timeout":"300","hard-timeout":"0"}]}}'
129 ----
130
131 * Get the Path policy information
132
133 ----
134 curl --user "admin":"admin" -H "Content-type: application/json" -X POST http://localhost:8181/restconf/operations/vtn-path-policy:set-path-policy -d '{"input":{"operation":"SET","id": "1","default-cost": "10000","vtn-path-cost": [{"port-desc":"openflow:1,3,s1-eth3","cost":"1000"},{"port-desc":"openflow:4,2,s4-eth2","cost":"100000"},{"port-desc":"openflow:3,3,s3-eth3","cost":"10000"}]}}'
135 ----
136
137 ===== Verification
138 * Before applying Path policy information in the VTN
139
140 ----
141 {
142         "pathinfos": [
143             {
144               "in_port_name": "s1-eth1",
145               "out_port_name": "s1-eth3",
146               "switch_id": "openflow:1"
147             },
148             {
149               "in_port_name": "s4-eth1",
150               "out_port_name": "s4-eth2",
151               "switch_id": "openflow:4"
152             },
153             {
154                "in_port_name": "s3-eth2",
155                "out_port_name": "s3-eth3",
156                "switch_id": "openflow:3"
157             }
158                      ]
159 }
160 ----
161 * After applying Path policy information in the VTN
162
163 ----
164 {
165     "pathinfos": [
166             {
167               "in_port_name": "s1-eth1",
168               "out_port_name": "s1-eth2",
169               "switch_id": "openflow:1"
170             },
171             {
172               "in_port_name": "s2-eth1",
173               "out_port_name": "s2-eth2",
174               "switch_id": "openflow:2"
175             },
176             {
177                "in_port_name": "s3-eth1",
178                "out_port_name": "s3-eth3",
179                "switch_id": "openflow:3"
180             }
181                      ]
182 }
183 ----
184