dc2e21c2075ac02c9c6280bfd9d467d1083404c5
[ovsdb.git] / ovsdb / src / test / java / org / opendaylight / ovsdb / OvsdbTestAddTunnel.java
1 package org.opendaylight.ovsdb;
2
3
4 import java.util.HashMap;
5 import java.util.Map;
6
7 import org.junit.Test;
8 import org.opendaylight.controller.sal.core.Node;
9 import org.opendaylight.controller.sal.core.NodeConnector;
10 import org.opendaylight.ovsdb.internal.*;
11 import org.opendaylight.ovsdb.sal.connection.ConnectionConstants;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14 import org.opendaylight.ovsdb.internal.Encapsulation;
15
16 public class OvsdbTestAddTunnel {
17     private static final Logger logger = LoggerFactory
18             .getLogger(OvsdbTestAddTunnel.class);
19
20     @Test
21     public void addTunnel() throws Throwable{
22         Node.NodeIDType.registerIDType("OVS", String.class);
23         NodeConnector.NodeConnectorIDType.registerIDType("OVS", String.class, "OVS");
24
25         ConnectionService connectionService = new ConnectionService();
26         connectionService.init();
27
28         String identifier = "TEST";
29         /**
30          * tunnelendpoint IP address of the
31          * destination Tunnel Endpoint.
32          * tunencap is the tunnel encapsulation
33          * options being (CAPWAP, GRE, VXLAN).
34          */
35         Encapsulation encap = Encapsulation.VXLAN;
36         String tunencap = encap.toString();
37         String tunnelendpoint = "192.168.100.100";
38
39         Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();
40         params.put(ConnectionConstants.ADDRESS, "172.16.58.170");
41
42         Node node = connectionService.connect(identifier, params);
43         if(node == null){
44             logger.error("Could not connect to ovsdb server");
45             return;
46         }
47         /**
48          * Create an Encapsulated Tunnel Interface and destination Tunnel Endpoint
49          * @param node Node serving this configuration service
50          * @param bridgeDomainIdentifier String representation of a Bridge Domain
51          * @param portIdentifier String representation of a user defined Port Name
52          * @param tunnelendpoint IP address of the destination Tunnel Endpoint
53          * @param tunencap is the tunnel encapsulation options being CAPWAP, GRE or VXLAN
54          * The Bridge must already be defined before calling addTunnel.
55          */
56         ConfigurationService configurationService = new ConfigurationService();
57         configurationService.setConnectionServiceInternal(connectionService);
58         configurationService.addTunnel(node, "JunitBridge",
59                 "tunnel0", tunnelendpoint, tunencap);
60     }
61 }