Porting the OVSDB services to use the Controller SAL services : Connection and Bridge...
[ovsdb.git] / ovsdb / src / test / java / org / opendaylight / ovsdb / OvsdbTestAddVlan.java
1 package org.opendaylight.ovsdb;
2
3 import org.junit.Test;
4 import org.opendaylight.controller.sal.core.Node;
5 import org.opendaylight.controller.sal.core.NodeConnector;
6 import org.opendaylight.ovsdb.internal.ConfigurationService;
7 import org.opendaylight.ovsdb.internal.ConnectionService;
8 import org.opendaylight.controller.sal.connection.ConnectionConstants;
9 import org.opendaylight.controller.sal.networkconfig.bridgedomain.ConfigConstants;
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
12 import java.util.HashMap;
13 import java.util.Map;
14
15 public class OvsdbTestAddVlan {
16     private static final Logger logger = LoggerFactory
17             .getLogger(OvsdbTestAddVlan.class);
18
19     @Test
20     public void addPortVlan() throws Throwable{
21         Node.NodeIDType.registerIDType("OVS", String.class);
22         NodeConnector.NodeConnectorIDType.registerIDType("OVS", String.class, "OVS");
23
24         ConnectionService connectionService = new ConnectionService();
25         connectionService.init();
26         String identifier = "TEST";
27         Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();
28         params.put(ConnectionConstants.ADDRESS, "172.28.30.51");
29         params.put(ConnectionConstants.PORT, "6634");
30         int vlanid = 100;
31
32         Node node = connectionService.connect(identifier, params);
33         if(node == null){
34             logger.error("Could not connect to ovsdb server");
35             return;
36         }
37         /**
38          * Create a Port with a user defined VLAN, and attach it to the specified bridge.
39          *
40          * Ex. ovs-vsctl add-port JUNIT_BRIDGE_TEST Jvlanvif0 tag=100
41          * @param node Node serving this configuration service
42          * @param bridgeDomainIdentifier String representation of a Bridge Domain
43          * @param portIdentifier String representation of a user defined Port Name
44          * @param vlanid Integer note: only one VID is accepted with tag=x method
45          */
46         ConfigurationService configurationService = new ConfigurationService();
47         configurationService.setConnectionServiceInternal(connectionService);
48         Map<ConfigConstants, Object> configs = new HashMap<ConfigConstants, Object>();
49         configs.put(ConfigConstants.TYPE, "VLAN");
50         configs.put(ConfigConstants.VLAN, vlanid+"");
51         configurationService.addPort(node, "JUNIT_BRIDGE_TEST", "Jtagvif0", configs);
52     }
53 }