Refactor of the OVSDB Plugin
[ovsdb.git] / plugin / src / test / java / org / opendaylight / ovsdb / plugin / BridgeDomainConfigPortTestCases.java
1 /*
2  * [[ Authors will Fill in the Copyright header ]]
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Authors : Brent Salisbury, Hugo Trippaers
9  */
10 package org.opendaylight.ovsdb.plugin;
11
12 import java.io.IOException;
13 import java.util.HashMap;
14 import java.util.Map;
15 import java.util.Properties;
16
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.controller.sal.core.Node;
20 import org.opendaylight.controller.sal.networkconfig.bridgedomain.ConfigConstants;
21 import org.opendaylight.ovsdb.plugin.impl.ConfigurationServiceImpl;
22 import org.opendaylight.ovsdb.plugin.impl.ConnectionServiceImpl;
23 import org.opendaylight.ovsdb.plugin.internal.Encapsulation;
24
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 public class BridgeDomainConfigPortTestCases extends PluginTestBase {
29     private static final Logger logger = LoggerFactory
30             .getLogger(BridgeDomainConfigPortTestCases.class);
31     private Properties props;
32
33     @Before
34     public void loadProps() throws IOException {
35         props = loadProperties();
36     }
37
38
39     /**
40      * Create a Port and attach it to a Bridge
41      * Ex. ovs-vsctl add-port br0 vif0
42      */
43
44     @Test
45     public void addPort() throws Throwable{
46         TestObjects testObjects = getTestConnection();
47         ConnectionServiceImpl connectionService = testObjects.connectionService;
48         Node node = testObjects.node;
49         ConfigurationServiceImpl configurationService = testObjects.configurationService;
50         configurationService.addPort(node, BRIDGE_NAME, PORT_NAME, null);
51     }
52
53     /**
54      * Create a Port with a user defined VLAN, and attach it to the specified bridge.
55      *
56      * Ex. ovs-vsctl add-port JUNIT_BRIDGE_TEST Jvlanvif0 tag=100
57      */
58     @Test
59     public void addPortVlan() throws Throwable{
60         TestObjects testObjects = getTestConnection();
61         ConnectionServiceImpl connectionService = testObjects.connectionService;
62         Node node = testObjects.node;
63
64         int vlanid = 100;
65
66         ConfigurationServiceImpl configurationService = testObjects.configurationService;
67         Map<ConfigConstants, Object> configs = new HashMap<ConfigConstants, Object>();
68         configs.put(ConfigConstants.TYPE, "VLAN");
69         configs.put(ConfigConstants.VLAN, vlanid+"");
70         configurationService.addPort(node, BRIDGE_NAME, TAGGED_PORT_NAME, configs);
71     }
72
73     /**
74      * Create an Encapsulated Tunnel Interface and destination Tunnel Endpoint
75      * tunnelendpoint IP address of the destination Tunnel Endpoint.
76      * tunencap is the tunnel encapsulation options being (CAPWAP, GRE, VXLAN).
77      *
78      * Ex. ovs-vsctl add-port br0 vxlan1 (cont)
79      * -- set interface vxlan1 type=vxlan options:remote_ip=192.168.1.11
80      */
81
82     @Test
83     public void addTunnel() throws Throwable{
84         TestObjects testObjects = getTestConnection();
85         Node node = testObjects.node;
86
87         Encapsulation encap = Encapsulation.VXLAN;
88         String tunencap = encap.toString();
89         String tunnelendpoint = FAKE_IP;
90
91         ConfigurationServiceImpl configurationService = testObjects.configurationService;
92         Map<ConfigConstants, Object> configs = new HashMap<ConfigConstants, Object>();
93         configs.put(ConfigConstants.TYPE, "TUNNEL");
94         configs.put(ConfigConstants.TUNNEL_TYPE, tunencap);
95         configs.put(ConfigConstants.DEST_IP, tunnelendpoint);
96
97         configurationService.addPort(node, BRIDGE_NAME, TUNNEL_PORT_NAME, configs);
98     }
99
100     /**
101      * Deletes an existing port from an existing bridge
102      * Ex. ovs-vsctl del-port ovsbr0 tap0
103      */
104     @Test
105     public void deletePort() throws Throwable{
106         TestObjects testObjects = getTestConnection();
107         ConnectionServiceImpl connectionService = testObjects.connectionService;
108         Node node = testObjects.node;
109
110         ConfigurationServiceImpl configurationService = testObjects.configurationService;
111         configurationService.deletePort(node, BRIDGE_NAME, PORT_NAME);
112     }
113
114 }