Merge "moving developers-guide to developer-guide for consistency"
[docs.git] / manuals / developer-guide / src / main / asciidoc / ovsdb.adoc
1 == OVSDB Integration\r
2 The Open vSwitch database (OVSDB) Plugin component for OpenDaylight implements the OVSDB  https://tools.ietf.org/html/rfc7047[RFC 7047] management protocol that allows the southbound configuration of vSwitches. The component comprises a library and various plugin usages.\r
3 The OVSDB protocol uses JSON/RPC calls to manipulate a physical or virtual switch that has OVSDB attached to it. Almost all vendors support OVSDB on various hardware platforms. The OpenDaylight controller uses the native OVSDB implementation to manipulate the Open vSwitch database. \r
4 \r
5 NOTE: Read the OVSDB User Guide before you begin development.\r
6 \r
7 === OpenDaylight OVSDB integration\r
8 \r
9 For information on how the GRE-endpoint destination IP address is communicated to the controller, see https://docs.google.com/presentation/d/19ua9U6nFJSO0wtenWmJUEzUFmib8ClTkkHTgZ_BvaMk/edit?pli=1#slide=id.g17727178e_180[Neutron and ODL interactions].\r
10 \r
11 The OpenStack integration architecture uses the following technologies: +\r
12 \r
13 * https://tools.ietf.org/html/rfc7047[RFC 7047] and http://datatracker.ietf.org/doc/rfc7047/[The Open vSwitch Database Management Protocol]\r
14 * OpenFlow v1.3\r
15 * OpenStack Neutron ML2 Plugin\r
16 \r
17 ==== Getting the code\r
18 ----\r
19 export ODL_USERNAME=<username for the account you created at OpenDaylight>\r
20 git clone ssh://${ODL_USERNAME}@git.opendaylight.org:29418/ovsdb.git;(cd ovsdb; scp -p -P 29418 ${ODL_USERNAME}@git.opendaylight.org:hooks/commit-msg .git/hooks/;chmod 755 .git/hooks/commit-msg;git config remote.origin.push HEAD:refs/for/master)\r
21 ----\r
22 \r
23 ==== OpenDaylight Mechanism Driver for Openstack Neutron ML2\r
24 This code is a part of OpenStack and is available at: https://github.com/openstack/neutron/blob/master/neutron/plugins/ml2/drivers/mechanism_odl.py\r
25 \r
26 To make changes to this code, please read about https://wiki.openstack.org/wiki/NeutronDevelopment[Neutron Development].\r
27 \r
28 Before submitting the code, run the following tests: +\r
29 ----\r
30 tox -e py27\r
31 tox -e pep8\r
32 ----\r
33 ==== Importing the code in to Eclipse or IntelliJ\r
34 Check out either of the following: +\r
35 \r
36 * https://wiki.opendaylight.org/view/Eclipse_Setup[Getting started with Eclipse]\r
37 * https://wiki.opendaylight.org/view/OpenDaylight_Controller:Developing_With_Intellij[Developing with Intellij]\r
38 \r
39 .Avoid conflicting project names\r
40 image::OVSDB_Eclipse.png[]\r
41 \r
42 * To ensure that a project in Eclipse does not have a conflicting name in the workspace, select Advanced > Name Template > [groupId].[artifactId] when importing the project.\r
43 \r
44 ==== Browsing the code\r
45 The code is mirrored to https://github.com/opendaylight/ovsdb[GitHub] to make reading code online easier. \r
46 \r
47 ==== Source code organization\r
48 \r
49 The OVSDB project generates 3 x Karaf Modules:\r
50 \r
51     ovsdb  -- all ovsdb related artifacts\r
52     of-nxm-extensions  -- openflow nxm extensions\r
53     ovs-sfc  -- openflow service chainning function\r
54 \r
55 Both of-nxm-extensions and ovs-sfc are expected to be moved out of the ovsdb source tree in the future.\r
56 \r
57 Following are a brief descriptions on directories you will find a the root ovsdb/ directory:\r
58 \r
59 * _commons_ contains the parent POM file for Maven project which is used to get consistency of settings across the project. \r
60 \r
61 * _distribution_ contains the OVSDB distribution. For OSGI, this is the latest Virtualization Edition pulled from the Integration project with your local OVSDB artifacts added. This gives developers the ability to run the controller for testing. \r
62 For Karaf, this is the latest Karaf bundle pulled from the Integration project, with your local OVSDB Karaf bundles mentioned above.\r
63 \r
64 * _openstack_ contains the northbound handlers for Neutron used by OVSDB, as well as their providers.\r
65 \r
66 * _resources_ contains useful scripts, How-To's and other resources.\r
67 \r
68 * _schemas_ contains the OVSDB schemas that are implemented in ODL.\r
69 \r
70 * _utils_ contains helper functions used for handling MD-SAL OpenFlow implementation.\r
71 \r
72 === Building and running OVSDB\r
73 *Prerequisites* +\r
74 \r
75 * JDK 1.7+\r
76 * Maven 3+\r
77 \r
78 [[ovsdbBuildSteps]]\r
79 ==== Building a Karaf feature and deploying it in an Opendaylight Karaf distribution +\r
80 This is a new method for Opendaylight distribution wherein there are no defined editions such \r
81 as Base, Virtualization, or SP editions.  The end-customer can choose to deploy the required feature based on user deployment needs.\r
82 \r
83 . From the root ovsdb/ directory, run *mvn clean install*.\r
84 . Unzip the distribution-karaf-<VERSION_NUMBER>-SNAPSHOT.zip file created from step 1 in the directory ovsdb/distribution/opendaylight-karaf/target:\r
85 ----\r
86 unzip distribution-karaf-<VERSION_NUMBER>-SNAPSHOT.zip\r
87 ----\r
88 ==== Downloading OVSDB's Karaf distribution +\r
89 Instead of building, you can download the latest OVSDB distribution from the Nexus server. The link for that is:\r
90 ----\r
91 http://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/org/opendaylight/ovsdb/distribution.ovsdb/1.2.0-SNAPSHOT/\r
92 ----\r
93 \r
94 ==== Running Karaf feature from OVSDB's Karaf distribution +\r
95 \r
96 [[ovsdbStartingOdl]]\r
97 . Start ODL, from the unzipped directory\r
98 ----\r
99 bin/karaf\r
100 ----\r
101 . Once karaf has started, and you see the Opendaylight ascii art in the console, the last step is to start the OVSDB plugin framework with the following command in the karaf console: \r
102 ----\r
103 feature:install odl-ovsdb-openstack\r
104 ----\r
105 \r
106 For ovsdb northbound, you will also need to invoke\r
107 ----\r
108 feature:install odl-ovsdb-northbound\r
109 ----\r
110 ===== Sample output from the Karaf console\r
111 ----\r
112 opendaylight-user@root>feature:list | grep -i ovsdb \r
113 odl-ovsdb-all                    | 1.0.0-SNAPSHOT      |           | ovsdb-1.0.0-SNAPSHOT        \r
114 OpenDaylight :: OVSDB :: all \r
115 odl-ovsdb-library                | 1.0.0-SNAPSHOT      | x         | ovsdb-1.0.0-SNAPSHOT        \r
116 OVSDB :: Library \r
117 odl-ovsdb-schema-openvswitch     | 1.0.0-SNAPSHOT      | x         | ovsdb-1.0.0-SNAPSHOT        \r
118 OVSDB :: Schema :: Open_vSwitch \r
119 odl-ovsdb-schema-hardwarevtep    | 1.0.0-SNAPSHOT      | x         | ovsdb-1.0.0-SNAPSHOT        \r
120 OVSDB :: Schema :: hardware_vtep\r
121 odl-ovsdb-plugin                 | 1.0.0-SNAPSHOT      | x         | ovsdb-1.0.0-SNAPSHOT        \r
122 OpenDaylight :: OVSDB :: Plugin\r
123 odl-ovsdb-northbound             | 0.6.0-SNAPSHOT      |           | ovsdb-1.0.0-SNAPSHOT        \r
124 OpenDaylight :: OVSDB :: Northbound \r
125 odl-ovsdb-openstack              | 1.0.0-SNAPSHOT      | x         | ovsdb-1.0.0-SNAPSHOT        \r
126 OpenDaylight :: OVSDB :: OpenStack Network Virtual \r
127 odl-ovsdb-ovssfc                 | 0.0.1-SNAPSHOT      |           | ovsdb-0.0.1-SNAPSHOT        \r
128 OpenDaylight :: OVSDB :: OVS Service Function Chai\r
129 odl-openflow-nxm-extensions      | 0.0.3-SNAPSHOT      | x         | ovsdb-0.0.3-SNAPSHOT        \r
130 OpenDaylight :: Openflow :: Nicira Extensions\r
131 ----\r
132 \r
133 ==== Testing patches\r
134 It is recommended that you test your patches locally before submission.\r
135  \r
136 ==== Neutron integration\r
137 To test patches to the Neutron integration, you need a http://devstack.org/guides/multinode-lab.html[Multi-Node Devstack Setup]. The ``resources`` folder contains sample ``local.conf`` files.\r
138 \r
139 ==== Open vSwitch\r
140 To test patches to the library, you will need a working http://openvswitch.org/[Open vSwitch]. Packages are available for most Linux distributions. If you would like to run multiple versions of Open vSwitch for testing you can use https://github.com/dave-tucker/docker-ovs[docker-ovs] to run Open vSwitch in https://www.docker.com/[Docker] containers. \r
141 \r
142 ==== Mininet\r
143 http://mininet.org/[Mininet] is another useful resource for testing patches. Mininet creates multiple Open vSwitches connected in a configurable topology. \r
144 \r
145 ==== Vagrant\r
146 \r
147 The Vagrant file in the root of the OVSDB source code provides an easy way to create VMs for tests. \r
148 \r
149 * To install Vagrant on your machine, follow the steps at: https://docs.vagrantup.com/v2/installation/[Installing Vagrant].\r
150 \r
151 *Testing with Devstack*\r
152 \r
153 . Start the controller.\r
154 ----\r
155 vagrant up devstack-control\r
156 vagrant ssh devstack-control\r
157 cd devstack\r
158 ./stack.sh\r
159 ----\r
160 [start=2]\r
161 . Run the following:\r
162 ----\r
163 vagrant up devstack-compute-1\r
164 vagrant ssh devstack-compute-1\r
165 cd devstack\r
166 ./stack.sh\r
167 ----\r
168 [start=3]\r
169 . To start testing, create a new VM.\r
170 ----\r
171 nova boot --flavor m1.tiny --image $(nova image-list | grep 'cirros-0.3.1-x86_64-uec\s' | awk '{print $2}') --nic net-id=$(neutron net-list | grep private | awk '{print $2}') test\r
172 ----\r
173 To create three, use the following:\r
174 ----\r
175 nova boot --flavor m1.tiny --image $(nova image-list | grep 'cirros-0.3.1-x86_64-uec\s' | awk '{print $2}') --nic net-id=$(neutron net-list | grep private | awk '{print $2}') --num-instances 3 test\r
176 ----\r
177 [start=4]\r
178 .To get a mininet installation for testing:\r
179 ----\r
180 vagrant up mininet\r
181 vagrant ssh mininet\r
182 ----\r
183 [start=5]\r
184 . Use the following to clean up when finished:\r
185 ----\r
186 vagrant destroy\r
187 ----\r
188 \r
189 === OVSDB integration design\r
190 ==== Resources\r
191 See the following: +\r
192 \r
193 * http://networkheresy.com/2012/09/15/remembering-the-management-plane/[Network Heresy]\r
194 \r
195 See the OVSDB YouTube Channel for getting started videos and other tutorials: +\r
196 \r
197 * http://www.youtube.com/channel/UCMYntfZ255XGgYFrxCNcAzA[ODL OVSDB Youtube Channel]\r
198 * https://wiki.opendaylight.org/view/OVSDB_Integration:Mininet_OVSDB_Tutorial[Mininet OVSDB Tutorial]\r
199 \r
200 === OpenDaylight OVSDB southbound plugin architecture and design\r
201 OpenVSwitch (OVS) is generally accepted as the unofficial standard for Virtual Switching in the Open hypervisor based solutions. Every other Virtual Switch implementation, properietery or otherwise, uses OVS in some form.\r
202 For information on OVS, see http://openvswitch.org/[Open vSwitch].\r
203 \r
204 In Software Defined Networking (SDN), controllers and applications interact using two channels: OpenFlow and OVSDB. OpenFlow addresses the forwarding-side of the OVS functionality. OVSDB, on the other hand, addresses the management-plane. \r
205 A simple and concise overview of Open Virtual Switch Database(OVSDB) is available at: http://networkstatic.net/getting-started-ovsdb/\r
206 \r
207 ==== Overview of OpenDaylight Controller architecture\r
208 The OpenDaylight controller platform is designed as a highly modular and plugin based middleware that serves various network applications in a variety of use-cases. The modularity is achieved through the Java OSGi framework. The controller consists of many Java OSGi bundles that work together to provide the required\r
209  controller functionalities. \r
210  \r
211 The bundles can be placed in the following broad categories: +\r
212 \r
213 * Network Service Functional Modules (Examples: Topology Manager, Inventory Manager, Forwarding Rules Manager,and others) \r
214 * NorthBound API Modules (Examples: Topology APIs, Bridge Domain APIs, Neutron APIs, Connection Manager APIs, and others) \r
215 * Service Abstraction Layer(SAL)- (Inventory Services, DataPath Services, Topology Services, Network Config, and others) \r
216 * SouthBound Plugins (OpenFlow Plugin, OVSDB Plugin, OpenDove Plugin, and others) \r
217 * Application Modules (Simple Forwarding, Load Balancer)\r
218 \r
219 Each layer of the Controller architecture performs specified tasks, and hence aids in modularity. \r
220 While the Northbound API layer addresses all the REST-Based application needs, the SAL layer takes care of abstracting the SouthBound plugin protocol specifics from the Network Service functions. \r
221  \r
222 Each of the SouthBound Plugins serves a different purpose, with some overlapping.\r
223 For example, the OpenFlow plugin might serve the Data-Plane needs of an OVS element, while the OVSDB plugin can serve the management plane needs of the same OVS element.\r
224 As the Openflow Plugin talks OpenFlow protocol with the OVS element, the OVSDB plugin will use OVSDB schema over JSON-RPC transport.\r
225 \r
226 === OVSDB southbound plugin\r
227 The http://tools.ietf.org/html/draft-pfaff-ovsdb-proto-02[Open vSwitch Database Management Protocol-draft-02] and http://openvswitch.org/ovs-vswitchd.conf.db.5.pdf[Open vSwitch Manual] provide theoretical information about OVSDB.\r
228 The OVSDB protocol draft is generic enough to lay the groundwork on Wire Protocol and Database Operations, and the OVS Manual currently covers 13 tables leaving space for future OVS expansion, and vendor expansions on proprietary implementations.\r
229 The OVSDB Protocol is a database records transport protocol using JSON RPC1.0. For information on the protocol structure, see http://networkstatic.net/getting-started-ovsdb/[Getting Started with OVSDB].\r
230 The OpenDaylight OVSDB southbound plugin consists of one or more OSGi bundles addressing the following services or functionalities: +\r
231 \r
232 * Connection Service - Based on Netty \r
233 * Network Configuration Service \r
234 * Bidirectional JSON-RPC Library \r
235 * OVSDB Schema definitions and Object mappers \r
236 * Overlay Tunnel management \r
237 * OVSDB to OpenFlow plugin mapping service \r
238 * Inventory Service \r
239 \r
240 === Connection service\r
241 One of the primary services that most southbound plugins provide to SAL in Opendaylight and NSF is Connection Service. The service provides protocol specific connectivity to network elements, and supports the connectivity management services as specified by the OpenDaylight Connection Manager. \r
242 The connectivity services include: +\r
243 \r
244 * Connection to a specified element given IP-address, L4-port, and other connectivity options (such as authentication,...) \r
245 * Disconnection from an element \r
246 * Handling Cluster Mode change notifications to support the OpenDaylight Clustering/High-Availability feature \r
247 \r
248 By default, the ovsdb-server process running on the hypervisor listens on TCP port 6632 (This is configurable.). The Connection Service takes the connectivity parameters from the connection manager, including the IP-address and TCP-Port for connections. Owing to the many benefits it provides, Connection Service will use the Netty framework (http://netty.io/) for connectivity purposes. \r
249 Every successful connection to a network element will result in a Node object (Refer to OpenDaylight SAL Node.java) with the type = "OVSDB" and value = User-Readable Name of the Connection as specified by the Connection Manager. This Node object is returned to the OpenDaylight Connection Manager and the application that invoked the Connect() functionality. \r
250 ----\r
251 IPluginInConnectionService : public Node connect(String identifier, Map<ConnectionConstants, String> params)\r
252 ----\r
253 Any subsequent interaction with this network element through any of the SAL services (Connection, Configuration, and others) will be by means of this Node Object. This Node object will be added to the Inventory maintained and managed by the Inventory Service of the plugin. The Node object will also assist with the OVSDB to Openflow mapping. \r
254 \r
255 The Node and its "Name" holds the key to the stateful Netty Socket handler maintained under the Connection Object created during the connect() call. The Channel concept of the Netty framework provides the much needed abstraction on the pipelining. With this Channel Pipelining and the asynchronous event handling, the message handling process gets better streamlined and understood. It also makes easier the replacement or manipulation of the pipeline functions in a more controlled fashion.\r
256 \r
257 .Connection to OVSDB server\r
258 image::ConnectionService.png[]\r
259 \r
260 .Successful connection handling\r
261 image::ConnectionServiceReturn.png[]\r
262 \r
263 === Network Configuration Service\r
264 \r
265 The goal of the OpenDaylight Network Configuration services is to provide complete management plane solutions needed to successfully install, configure, and deploy the various SDN based network services. These are generic services which can be implemented in part or full by any south-bound protocol plugin. \r
266 The south-bound plugins can be either of the following: +\r
267 \r
268 * The new network virtualization protocol plugins such as OVSDB JSON-RPC\r
269 * The traditional management protocols such as SNMP or any others in the middle. \r
270 \r
271 The above definition, and more information on Network Configuration Services, is available at : https://wiki.opendaylight.org/view/OpenDaylight_Controller:NetworkConfigurationServices \r
272 \r
273 The current default OVSDB schemas support the Layer2 Bridge Domain services as defined in the Networkconfig.bridgedomain component. \r
274 \r
275 * Create Bridge Domain: createBridgeDomain(Node node, String bridgeIdentifier, Map<ConfigConstants, Object> params) \r
276 * Delete Bridge Domain: deleteBridgeDomain(Node node, String bridgeIdentifier) \r
277 * Add configurations to a Bridge Domain: addBridgeDomainConfig(Node node, String bridgeIdentifier, Map<ConfigConstants, Object> params) \r
278 * Delete Bridge Domain Configuration: removeBridgeDomainConfig(Node node, String bridgeIdentifier, Map<ConfigConstants, Object> params) \r
279 * Associate a port to a Bridge Domain: addPort(Node node, String bridgeIdentifier, String portIdentifier, Map<ConfigConstants, Object> params); \r
280 * Disassociate a port from a Bridge Domain: deletePort(Node node, String bridgeIdentifier, String portIdentifier) \r
281 * Add configurations to a Node Connector / Port: addPortConfig(Node node, String bridgeIdentifier, String portIdentifier, Map<ConfigConstants, Object> params) \r
282 * Remove configurations from a Node Connector: removePortConfig(Node node, String bridgeIdentifier, String portIdentifier, Map<ConfigConstants, Object> params) \r
283 \r
284 The above services are defined as generalized entities in SAL in order to ensure their compatibility with all relevant southBound plugins equally. Hence, the OVSDB plugin must derive appropriate specific configurations from a generalized request. For example: addPort() or addPortConfig() SAL service call takes in a params option which is a Map structure with a Constant Key. \r
285 These ConfigConstants are defined in SAL network configuration service: +\r
286 ----\r
287 public enum ConfigConstants {\r
288     TYPE("type"),\r
289     VLAN("Vlan"),\r
290     VLAN_MODE("vlan_mode"),\r
291     TUNNEL_TYPE("Tunnel Type"),\r
292     SOURCE_IP("Source IP"),\r
293     DEST_IP("Destination IP"),\r
294     MACADDRESS("MAC Address"),\r
295     INTERFACE_IDENTIFIER("Interface Identifier"),\r
296     MGMT("Management"),\r
297     CUSTOM("Custom Configurations");\r
298 }\r
299 ----\r
300 These are mapped to the appropriate OVSDB configurations. So, if the request is to create a VXLAN tunnel with src-ip=x.x.x.x, dst-ip=y.y.y.y, then the params Map structure may contain:\r
301 ----\r
302 {\r
303 TYPE = "tunnel",\r
304 TUNNEL_TYPE = "vxlan",\r
305 SOURCE_IP="x.x.x.x",\r
306 DEST_IP="y.y.y.y"\r
307 }\r
308 ----\r
309 NOTE: All of the APIs take in the Node parameter which is the Node value returned by the connect() method explained in <<_connection_service>>.\r
310 \r
311 ==== Bidirectional JSON-RPC library\r
312 The OVSDB plugin implements a Bidirectional JSON-RPC library.  It is easy to design the library as a module that manages the Netty connection towards the Element. \r
313 \r
314 The main responsibilities of this Library are: +\r
315 \r
316 * Demarshal and marshal JSON Strings to JSON objects \r
317 * Demarshal and marshal JSON Strings from and to the Network Element.\r
318 \r
319 ==== OVSDB Schema definitions and Object mappers\r
320 The OVSDB Schema definitions and Object Mapping layer sits above the JSON-RPC library. It maps the generic JSON objects to OVSDB schema POJOs (Plain Old Java Object) and vice-versa. This layer mostly provides the Java Object definition for the corresponding OVSDB schema (13 of them) and also will provide much more friendly API abstractions on top of these object data. This helps in hiding the JSON semantics from the functional modules such as Configuration Service and Tunnel management.\r
321 \r
322 On the demarshaling side, the mapping logic differentiates the Request and Response messages as follows : +\r
323 \r
324 * Request messages are mapped by its "method" \r
325 * Response messages are mapped by their IDs which were originally populated by the Request message.\r
326 The JSON semantics of these OVSDB schema is quite complex.\r
327 The following figures summarize two of the end-to-end scenarios: +\r
328 \r
329 .End-to-end handling of a Create Bridge request \r
330 image::ConfigurationService-example1.png[width=500]\r
331 \r
332 .End-to-end handling of a monitor response\r
333 image::MonitorResponse.png[width=500]\r
334 \r
335 ==== Overlay tunnel management\r
336 \r
337 Network Virtualization using OVS is achieved through Overlay Tunnels. The actual Type of the Tunnel may be GRE, VXLAN, or STT. The differences in the encapsulation and configuration decide the tunnel types. Establishing a tunnel using configuration service requires just the sending of OVSDB messages towards the ovsdb-server. However, the scaling issues that would arise on the state management at the data-plane (using OpenFlow) can get challenging. Also, this module can assist in various optimizations in the presence of Gateways. It can also help in providing Service guarantees for the VMs using these overlays with the help of underlay orchestration. \r
338 \r
339 ==== OVSDB to OpenFlow plugin mapping service\r
340 The connect() of the ConnectionService  would result in a Node that represents an ovsdb-server. The CreateBridgeDomain() Configuration on the above Node would result in creating an OVS bridge. This OVS Bridge is an OpenFlow Agent for the OpenDaylight OpenFlow plugin with its own Node represented as (example) OF|xxxx.yyyy.zzzz. \r
341 Without any help from the OVSDB plugin, the Node Mapping Service of the Controller platform would not be able to map the following: +\r
342 ----\r
343 {OVSDB_NODE + BRIDGE_IDENTFIER} <---> {OF_NODE}.\r
344 ----\r
345 Without such mapping, it would be extremely difficult for the applications to manage and maintain such nodes. This Mapping Service provided by the OVSDB plugin would essentially help in providing more value added services to the orchestration layers that sit atop the Northbound APIs (such as OpenStack). \r
346 \r
347 ==== Inventory service\r
348 \r
349 Inventory Service provides a simple database of all the nodes managed and maintained by the OVSDB plugin on a given controller. For optimization purposes, it can also provide enhanced services to the OVSDB to OpenFlow mapping service by maintaining the following mapping owing to the static nature of this operation. +\r
350 ----\r
351 {OVSDB_NODE + BRIDGE_IDENTFIER} <---> {OF_NODE}\r
352 ----\r
353 === OpenDaylight OVSDB Developer Getting Started Video Series\r
354 The video series were started to help developers bootstrap into OVSDB development.\r
355 \r
356 * http://www.youtube.com/watch?v=ieB645oCIPs[OpenDaylight OVSDB Developer Getting Started]\r
357 * http://www.youtube.com/watch?v=xgevyaQ12cg[OpenDaylight OVSDB Developer Getting Started - Northbound API Usage]\r
358 * http://www.youtube.com/watch?v=xgevyaQ12cg[OpenDaylight OVSDB Developer Getting Started - Java APIs]\r
359 * http://www.youtube.com/watch?v=NayuY6J-AMA[OpenDaylight OVSDB Developer Getting Started - OpenStack Integration OpenFlow v1.0]\r
360 \r
361 ==== Other developer tutorials\r
362 \r
363 * https://wiki.opendaylight.org/view/OVSDB:OVSDB_OpenStack_Guide[OVSDB OpenFlow v1.3 Neutron ML2 Integration]\r
364 * http://networkstatic.net/getting-started-ovsdb/[Open vSwitch Database Table Explanations and Simple Jackson Tutorial]\r
365 \r
366 === OVSDB integration: New features\r
367 ==== Schema independent library\r
368 The OVS connection is a node which can have multiple databases. Each database is represented by a schema. A single connection can have multiple schemas.\r
369 OSVDB supports multiple schemas. Currently, these are two schemas available in the\r
370 OVSDB, but there is no restriction on the number of schemas. Owing to the Northbound v3 API, no code changes in ODL are needed for supporting additional schemas.\r
371 \r
372 Schemas: +\r
373 \r
374 *  openvswitch : Schema wrapper that represents http://openvswitch.org/ovs-vswitchd.conf.db.5.pdf\r
375 *  hardwarevtep: Schema wrapper that represents http://openvswitch.org/docs/vtep.5.pdf\r
376 \r
377 ==== Northbound API v3\r
378 OVSDB supports Northbound API v3 which allows external access to all ODL OVSDB databases or schemas.\r
379 The general syntax for that API follows this format:\r
380 ----\r
381 http://{{controllerHost}}:{{controllerPort}}/ovsdb/nb/v3/node/{{OVS|HOST}}/database\r
382 ---- \r
383 For more information on Northbound REST API see: +\r
384 https://docs.google.com/spreadsheets/d/11Rp5KSNTcrvOD4HadCnXDCUdJq_TZ5RgoQ6qSHf_xkw/edit?usp=sharing\r
385  \r
386 The key differences between Northbound API v2 and v3 include: +\r
387  \r
388 * Support for schema independence\r
389 * Formal restful style API, which includes consistent URL navigation for nodes and tables\r
390 * Ability to create interfaces and ports within a single rest call. To allow that, the JSON in the body can include distinct parts like interface and port\r
391 \r
392 ==== Port security\r
393 Based on the fact that security rules can be obtained from a port object, OVSDB can apply Open Flow rules. These rules will match on what types of traffic the Openstack tenant VM is allowed to use.\r
394  \r
395 Support for security groups is very experimental. There are limitations in determining the state of flows in the Open vSwitch. See http://%20https//www.youtube.com/watch?v=DSop2uLJZS8[Open vSwitch and the Intelligent Edge] from Justin Petit for a deep dive into the challenges we faced creating a flow based port security implementation. The current set of rules that will be installed only supports filtering of the TCP protocol. This is because via a Nicira TCP_Flag read we can match on a flows TCP_SYN flag, and permit or deny the flow based on the Neutron port security rules. If rules are requested for ICMP and UDP, they are ignored until greater visibility from the Linux kernel is available as outlined in the OpenStack presentation mentioned earlier. \r
396 \r
397 Using the port security groups of Neutron, one can add rules that restrict the network access of the tenants. The OVSDB Neutron integration checks the port security rules configured, and apply them by means of openflow rules. \r
398 \r
399 Through the ML2 interface, Neutron security rules are available in the port object, following this scope: Neutron Port -> Security Group -> Security Rules. \r
400 \r
401 The current rules are applied on the basis of the following attributes: ingress/egress, tcp protocol, port range, and prefix.\r
402  \r
403 ===== OpenStack workflow\r
404 \r
405 . Create a stack.\r
406 . Add the network and subnet. \r
407 . Add the Security Group and Rules.\r
408 \r
409 NOTE: This is no different than what users normally do in regular openstack deployments. \r
410 ----\r
411 neutron security-group-create group1 --description "Group 1"\r
412 neutron security-group-list\r
413 neutron security-group-rule-create --direction ingress --protocol tcp group1\r
414 ----\r
415 [start=4]\r
416 . Start the tenant, specifying the security-group.\r
417 ----\r
418 nova boot --flavor m1.tiny \\r
419 --image $(nova image-list | grep 'cirros-0.3.1-x86_64-uec\s' | awk '{print $2}') \\r
420 --nic net-id=$(neutron net-list | grep 'vxlan2' | awk '{print $2}') vxlan2 \\r
421 --security-groups group1\r
422 ----\r
423 ===== Examples: Rules supported\r
424 ----\r
425 neutron security-group-create group2 --description "Group 2"\r
426 neutron security-group-rule-create --direction ingress --protocol tcp --port-range-min 54 group2\r
427 neutron security-group-rule-create --direction ingress --protocol tcp --port-range-min 80 group2\r
428 neutron security-group-rule-create --direction ingress --protocol tcp --port-range-min 1633 group2\r
429 neutron security-group-rule-create --direction ingress --protocol tcp --port-range-min 22 group2\r
430 ----\r
431 ----\r
432 neutron security-group-create group3 --description "Group 3"\r
433 neutron security-group-rule-create --direction ingress --protocol tcp --remote-ip-prefix 10.200.0.0/16 group3\r
434 ----\r
435 ----\r
436 neutron security-group-create group4 --description "Group 4"\r
437 neutron security-group-rule-create --direction ingress --remote-ip-prefix 172.24.0.0/16 group4\r
438 ----\r
439 ----\r
440 neutron security-group-create group5 --description "Group 5"\r
441 neutron security-group-rule-create --direction ingress --protocol tcp group5\r
442 neutron security-group-rule-create --direction ingress --protocol tcp --port-range-min 54 group5\r
443 neutron security-group-rule-create --direction ingress --protocol tcp --port-range-min 80 group5\r
444 neutron security-group-rule-create --direction ingress --protocol tcp --port-range-min 1633 group5\r
445 neutron security-group-rule-create --direction ingress --protocol tcp --port-range-min 22 group5\r
446 ----\r
447 ----\r
448 neutron security-group-create group6 --description "Group 6"\r
449 neutron security-group-rule-create --direction ingress --protocol tcp --remote-ip-prefix 0.0.0.0/0 group6\r
450 ----\r
451 ----\r
452 neutron security-group-create group7 --description "Group 7"\r
453 neutron security-group-rule-create --direction egress --protocol tcp --port-range-min 443 --remote-ip-prefix 172.16.240.128/25 group7\r
454 ----\r
455 *Reference gist*:https://gist.github.com/anonymous/1543a410d57f491352c8[Gist]\r
456 \r
457 ===== Security group rules supported in ODL \r
458 The following rules formata are supported in the current implementation. The direction (ingress/egress) is always expected. Rules are implemented such that tcp-syn packets that do not satisfy the rules are dropped.\r
459 [cols="3", width="60%"]\r
460 |===\r
461 | Proto | Port | IP Prefix\r
462 \r
463 |TCP |x |x\r
464 |Any | Any |x\r
465 |TCP |x |Any\r
466 |TCP |Any |Any\r
467 |===\r
468 ===== Limitations\r
469 \r
470 * Soon, conntrack will be supported by OVS. Until then, TCP flags are used as way of checking for connection state. Specifically, that is done by matching on the TCP-SYN flag. \r
471 * The param '--port-range-max' in 'security-group-rule-create' is not used until the implementation uses contrack. \r
472 * No UDP/ICMP specific match support is provided.\r
473 * No IPv6 support is provided.\r
474 \r
475 ==== L3 forwarding\r
476 OVSDB extends support for the usage of an ODL-Neutron-driver so that OVSDB can configure OF 1.3 rules to route IPv4 packets. The driver eliminates the need for the router of the L3 Agent. In order to accomplish that, OVS 2.1 or a newer version is required.\r
477 OVSDB also supports inbound/outbound NAT, floating IPs.\r
478 \r
479 ===== Starting OVSDB and OpenStack\r
480 \r
481 . Build or download OVSDB distribution, as mentioned in <<ovsdbBuildSteps,building a Karaf feature section>>.\r
482 . http://docs.vagrantup.com/v2/installation/index.html[Install Vagrant].\r
483 \r
484 [start=3]\r
485 . Enable the L3 Forwarding feature:\r
486 ----\r
487 echo 'ovsdb.l3.fwd.enabled=yes' >> ./opendaylight/configuration/config.ini\r
488 echo 'ovsdb.l3gateway.mac=${GATEWAY_MAC}' >> ./configuration/config.ini\r
489 ----\r
490 [start=4]\r
491 . Run the following commands to get the odl neutron drivers:\r
492 [start=5]\r
493 ----\r
494 git clone https://github.com/dave-tucker/odl-neutron-drivers.git\r
495 cd odl-neutron-drivers\r
496 vagrant up devstack-control devstack-compute-1\r
497 ----\r
498 [start=6]\r
499 . Use ssh to go to the control node, and clone odl-neutron-drivers again:\r
500 ----\r
501 vagrant ssh devstack-control\r
502 git clone https://github.com/dave-tucker/odl-neutron-drivers.git\r
503 cd odl-neutron-drivers\r
504 sudo python setup.py install\r
505 *leave this shell open*\r
506 ----\r
507 [start=7]\r
508 . Start odl, as mentioned in <<ovsdbStartingOdl,running Karaf feature section>>.\r
509 [start=8]\r
510 . To see processing of neutron event related to L3, do this from prompt:\r
511 ----\r
512 log:set debug org.opendaylight.ovsdb.openstack.netvirt.impl.NeutronL3Adapter\r
513 ----\r
514 [start=9]\r
515 . From shell, do one of the following: open on ssh into control node or vagrant ssh devstack-control.\r
516 ----\r
517 cd ~/devstack && ./stack.sh\r
518 ----\r
519 [start=10]\r
520 . From a new shell in the host system, run the following:\r
521 ----\r
522 cd odl-neutron-drivers\r
523 vagrant ssh devstack-compute-1\r
524 cd ~/devstack && ./stack.sh\r
525 ----\r
526 ===== OpenStack workflow\r
527 \r
528 .Sample workflow\r
529 image::L3FwdSample.png[height=250]\r
530 \r
531 Use the following steps to set up a workflow like the one shown in figure above.\r
532 \r
533 . Set up authentication. From shell on stack control or vagrant ssh devstack-control:\r
534 ----\r
535 source openrc admin admin\r
536 ----\r
537 \r
538 ----\r
539 rm -f id_rsa_demo* ; ssh-keygen -t rsa -b 2048 -N  -f id_rsa_demo\r
540  nova keypair-add --pub-key  id_rsa_demo.pub  demo_key\r
541  # nova keypair-list\r
542 ----\r
543 [start=2]\r
544 . Create two networks and two subnets.\r
545 ----\r
546 neutron net-create net1 --tenant-id $(keystone tenant-list | grep '\s'admin | awk '{print $2}') \\r
547  --provider:network_type gre --provider:segmentation_id 555\r
548 ----\r
549 ----\r
550 neutron subnet-create --tenant-id $(keystone tenant-list | grep '\s'admin | awk '{print $2}') \\r
551 net1 10.0.0.0/16 --name subnet1 --dns-nameserver 8.8.8.8\r
552 ----\r
553 ----\r
554 neutron net-create net2 --tenant-id $(keystone tenant-list | grep '\s'admin | awk '{print $2}') \\r
555  --provider:network_type gre --provider:segmentation_id 556\r
556 ----\r
557 ----\r
558 neutron subnet-create --tenant-id $(keystone tenant-list | grep '\s'admin | awk '{print $2}') \\r
559  net2 20.0.0.0/16 --name subnet2 --dns-nameserver 8.8.8.8\r
560 ----\r
561 [start=3]\r
562 . Create a router, and add an interface to each of the two subnets.\r
563 ----\r
564 neutron router-create demorouter --tenant-id $(keystone tenant-list | grep '\s'admin | awk '{print $2}')\r
565  neutron router-interface-add demorouter subnet1\r
566  neutron router-interface-add demorouter subnet2\r
567  # neutron router-port-list demorouter\r
568 ----\r
569 [start=4]\r
570 . Create two tenant instances.\r
571 ----\r
572 nova boot --poll --flavor m1.nano --image $(nova image-list | grep 'cirros-0.3.2-x86_64-uec\s' | awk '{print $2}') \\r
573  --nic net-id=$(neutron net-list | grep -w net1 | awk '{print $2}'),v4-fixed-ip=10.0.0.10 \\r
574  --availability-zone nova:devstack-control \\r
575  --key-name demo_key host10\r
576 ----\r
577 ----\r
578 nova boot --poll --flavor m1.nano --image $(nova image-list | grep 'cirros-0.3.2-x86_64-uec\s' | awk '{print $2}') \\r
579  --nic net-id=$(neutron net-list | grep -w net2 | awk '{print $2}'),v4-fixed-ip=20.0.0.20 \\r
580  --availability-zone nova:devstack-compute-1 \\r
581  --key-name demo_key host20\r
582 ----\r
583 \r
584 ===== Limitations\r
585 \r
586 * To use this feature, you need OVS 2.1 or newer version. \r
587 * Owing to OF limitations, icmp responses due to routing failures, like ttl expired or host unreacheable, are not generated.\r
588 * The MAC address of the default route is not automatically mapped. In order to route to L3 destinations outside the networks of the tenant, the manual configuration of the default route is necessary. To provide the MAC address of the default route, use ovsdb.l3gateway.mac in file configuration/config.ini ; \r
589 * This feature is Tech preview, which depends on later versions of OpenStack to be used without the provided neutron-driver. \r
590 * No IPv6 support is provided.\r
591  \r
592 *More information on L3 forwarding*: +\r
593 \r
594 * odl-neutron-driver: https://github.com/dave-tucker/odl-neutron-drivers\r
595 * OF rules example: http://dtucker.co.uk/hack/building-a-router-with-openvswitch.html\r
596 \r
597 ==== LBaaS\r
598 Load-Balancing-as-a-Service (LBaaS) creates an Open vSwitch powered L3-L4 stateless load-balancer in a virtualized network environment so that individual TCP connections destined to a designated virtual IP (VIP) are sent to the appropriate servers (that is to say, serving app VMs). The load-balancer works in a session-preserving, proactive manner without involving the controller during flow setup.\r
599 \r
600 A Neutron northbound interface is provided to create a VIP which will map to a pool of servers (that is to say, members) within a subnet. The pools consist of members identified by an IP address. The goal is to closely match the API to the OpenStack LBaaS v2 API: http://docs.openstack.org/api/openstack-network/2.0/content/lbaas_ext.html.\r
601 \r
602 ===== Creating an OpenStack workflow\r
603 . Create a subnet. \r
604 . Create a floating VIP 'A' that maps to a private VIP 'B'. \r
605 . Create a Loadbalancer pool 'X'. \r
606 ----\r
607 neutron lb-pool-create --name http-pool --lb-method ROUND_ROBIN --protocol HTTP --subnet-id XYZ\r
608 ----\r
609 [start=4]\r
610 . Create a Loadbalancer pool member 'Y' and associate with pool 'X'. \r
611 ----\r
612 neutron lb-member-create --address 10.0.0.10 --protocol-port 80 http-pool\r
613 neutron lb-member-create --address 10.0.0.11 --protocol-port 80 http-pool\r
614 neutron lb-member-create --address 10.0.0.12 --protocol-port 80 http-pool\r
615 neutron lb-member-create --address 10.0.0.13 --protocol-port 80 http-pool\r
616 ----\r
617 [start=5]\r
618 . Create a Loadbalancer instance 'Z', and associate pool 'X' and VIP 'B' with it.\r
619 ----\r
620 neutron lb-vip-create --name http-vip --protocol-port 80 --protocol HTTP --subnet-id XYZ http-pool\r
621 ----\r
622 \r
623 ===== Implementation\r
624 \r
625 The current implementation of the proactive stateless load-balancer was made using "multipath" action in the Open vSwitch. The "multipath" action takes a max_link parameter value (which is same as the number of pool members) as input, and performs a hash of the fields to get a value between (0, max_link). The value of the hash is used as an index to select a pool member to handle that session. \r
626 \r
627 ==== Open vSwitch rules\r
628 \r
629 Assuming that table=20 contains all the rules to forward the traffic destined for a specific destination MAC address, the following are the rules needed to be programmed in the LBaaS service table=10. The programmed rules makes the translation from the VIP to a different pool member for every session. \r
630 \r
631 * Proactive forward rules:\r
632 ----\r
633 sudo ovs-ofctl -O OpenFlow13 add-flow s1 "table=10,reg0=0,ip,nw_dst=10.0.0.5,actions=load:0x1->NXM_NX_REG0[[]],multipath(symmetric_l4, 1024, modulo_n, 4, 0, NXM_NX_REG1[0..12]),resubmit(,10)"\r
634 sudo ovs-ofctl -O OpenFlow13 add-flow s1 table=10,reg0=1,nw_dst=10.0.0.5,ip,reg1=0,actions=mod_dl_dst:00:00:00:00:00:10,mod_nw_dst:10.0.0.10,goto_table:20\r
635 sudo ovs-ofctl -O OpenFlow13 add-flow s1 table=10,reg0=1,nw_dst=10.0.0.5,ip,reg1=1,actions=mod_dl_dst:00:00:00:00:00:11,mod_nw_dst:10.0.0.11,goto_table:20\r
636 sudo ovs-ofctl -O OpenFlow13 add-flow s1 table=10,reg0=1,nw_dst=10.0.0.5,ip,reg1=2,actions=mod_dl_dst:00:00:00:00:00:12,mod_nw_dst:10.0.0.12,goto_table:20\r
637 sudo ovs-ofctl -O OpenFlow13 add-flow s1 table=10,reg0=1,nw_dst=10.0.0.5,ip,reg1=3,actions=mod_dl_dst:00:00:00:00:00:13,mod_nw_dst:10.0.0.13,goto_table:20\r
638 ----\r
639 * Proactive reverse rules: \r
640 ----\r
641 sudo ovs-ofctl -O OpenFlow13 add-flow s1 table=10,ip,tcp,tp_src=80,actions=mod_dl_src:00:00:00:00:00:05,mod_nw_src:10.0.0.5,goto_table:20\r
642 ---- \r
643 ===== OVSDB project code\r
644 The current implementation handles all neutron calls in the net-virt/LBaaSHandler.java code, and makes calls to the net-virt-providers/LoadBalancerService to program appropriate flowmods. The rules are updated whenever there is a change in the Neutron LBaaS settings. There is no cache of state kept in the net-virt or providers. \r
645 \r
646 ===== Limitations\r
647 Owing to the inflexibility of the multipath action, the existing LBaaS implementation comes with some limitations: \r
648 \r
649 * TCP, HTTP or HTTPS are supported protocols for the pool. (Caution: You can lose access to the members if you assign {Proto:TCP, Port:22} to LB) \r
650 \r
651 * Member weights are ignored. \r
652 * The update of an LB instance is done as a delete + add, and not an actual delta. \r
653 * The update of an LB member is not supported (because weights are ignored). \r
654 * Deletion of an LB member leads to the reprogramming of the LB on all nodes (because of the way multipath does link hash).\r
655 * There is only a single LB instance per subnet because the pool-id is not reported in the create load-balancer call. \r
656 \r
657 \r
658 \r
659 \r
660 \r
661 \r
662 \r
663 \r
664 \r
665                        \r
666 \r
667 \r