1 package org.opendaylight.ovsdb.internal;
3 import java.net.InetAddress;
6 import org.opendaylight.ovsdb.database.OVSBridge;
7 import org.opendaylight.ovsdb.database.OVSInstance;
8 import org.opendaylight.ovsdb.sal.configuration.IPluginInNetworkConfigurationService;
9 import org.opendaylight.controller.sal.core.Node;
10 import org.opendaylight.controller.sal.core.NodeConnector;
11 import org.opendaylight.ovsdb.database.Uuid;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
15 public class ConfigurationService implements IPluginInNetworkConfigurationService
17 private static final Logger logger = LoggerFactory
18 .getLogger(ConfigurationService.class);
20 IConnectionServiceInternal connectionService;
26 * Function called by the dependency manager when at least one dependency
27 * become unsatisfied or when the component is shutting down because for
28 * example bundle is being stopped.
35 * Function called by dependency manager after "init ()" is called and after
36 * the services provided by the class are registered in the service registry
43 * Function called by the dependency manager before the services exported by
44 * the component are unregistered, this will be followed by a "destroy ()"
51 public void setConnectionServiceInternal(IConnectionServiceInternal connectionService) {
52 this.connectionService = connectionService;
55 public void unsetConnectionServiceInternal(IConnectionServiceInternal connectionService) {
56 if (this.connectionService == connectionService) {
57 this.connectionService = null;
63 * @param node Node serving this configuration service
64 * @param bridgeConnectorIdentifier String representation of a Bridge Connector
65 * @return Bridge Connector configurations
68 @SuppressWarnings("unchecked")
69 public boolean createBridgeDomain(Node node, String bridgeIdentifier) throws Throwable{
71 if (connectionService == null) {
72 logger.error("Couldn't refer to the ConnectionService");
76 Connection connection = connectionService.getConnection(node);
77 String identifier = "TEST";
79 if (connection != null) {
80 String newBridge = "new_bridge";
81 String newInterface = "new_interface";
82 String newPort = "new_port";
83 String newSwitch = "new_switch";
85 Object addSwitchRequest;
87 OVSInstance instance = new OVSInstance();
88 instance.monitorOVS(connection);
90 if(instance.getUuid() != null){
91 List<String> bridgeUuidPair = new ArrayList<String>();
92 bridgeUuidPair.add("named-uuid");
93 bridgeUuidPair.add(newBridge);
95 List<Object> mutation = new ArrayList<Object>();
96 mutation.add("bridges");
97 mutation.add("insert");
98 mutation.add(bridgeUuidPair);
100 List<Object> mutations = new ArrayList<Object>();
101 mutations.add(mutation);
103 List<String> ovsUuidPair = new ArrayList<String>();
104 ovsUuidPair.add("uuid");
105 ovsUuidPair.add(instance.getUuid());
107 List<Object> whereInner = new ArrayList<Object>();
108 whereInner.add("_uuid");
109 whereInner.add("==");
110 whereInner.add(ovsUuidPair);
112 List<Object> where = new ArrayList<Object>();
113 where.add(whereInner);
115 addSwitchRequest = new MutateRequest("Open_vSwitch", where, mutations);
118 Map<String, Object> vswitchRow = new HashMap<String, Object>();
119 ArrayList<String> bridges = new ArrayList<String>();
120 bridges.add("named-uuid");
121 bridges.add(newBridge);
122 vswitchRow.put("bridges", bridges);
123 addSwitchRequest = new InsertRequest("insert", "Open_vSwitch", newSwitch, vswitchRow);
126 Map<String, Object> bridgeRow = new HashMap<String, Object>();
127 bridgeRow.put("name", bridgeIdentifier);
128 ArrayList<String> ports = new ArrayList<String>();
129 ports.add("named-uuid");
131 bridgeRow.put("ports", ports);
132 InsertRequest addBridgeRequest = new InsertRequest("insert", "Bridge", newBridge, bridgeRow);
134 Map<String, Object> portRow = new HashMap<String, Object>();
135 portRow.put("name", bridgeIdentifier);
136 ArrayList<String> interfaces = new ArrayList<String>();
137 interfaces.add("named-uuid");
138 interfaces.add(newInterface);
139 portRow.put("interfaces", interfaces);
140 InsertRequest addPortRequest = new InsertRequest("insert", "Port", newPort, portRow);
142 Map<String, Object> interfaceRow = new HashMap<String, Object>();
143 interfaceRow.put("name", bridgeIdentifier);
144 interfaceRow.put("type", "internal");
145 InsertRequest addIntfRequest = new InsertRequest("insert", "Interface", newInterface, interfaceRow);
147 Object[] params = {"Open_vSwitch", addSwitchRequest, addIntfRequest, addPortRequest, addBridgeRequest};
148 OvsdbMessage msg = new OvsdbMessage("transact", params);
150 connection.sendMessage(msg);
151 connection.readResponse(Uuid[].class);
160 public boolean deleteBridgeDomain(Node node, String bridgeIdentifier) {
161 // TODO Auto-generated method stub
166 public List<String> getBridgeDomains(Node node) {
167 // TODO Auto-generated method stub
172 public boolean addBridgeDomainConfig(Node node, String bridgeIdentifier, Map<String, String> config) {
173 // TODO Auto-generated method stub
178 public boolean removeBridgeDomainConfig(Node node, String bridgeIdentifier, Map<String, String> config) {
179 // TODO Auto-generated method stub
184 public Map<String, String> getBridgeDomainConfigs(Node node, String bridgeIdentifier) {
185 // TODO Auto-generated method stub
190 public boolean createBridgeConnector(Node node, String bridgeConnectorIdentifier) {
191 // TODO Auto-generated method stub
196 public boolean deleteBridgeConnector(Node node, String bridgeConnectorIdentifier) {
197 // TODO Auto-generated method stub
202 public boolean associateBridgeConnector(Node node, String bridgeIdentifier, String bridgeConnectorIdentifier) {
203 // TODO Auto-generated method stub
208 public boolean disassociateBridgeConnector(Node node, String bridgeIdentifier, String bridgeConnectorIdentifier) {
209 // TODO Auto-generated method stub
214 public boolean addBridgeConnectorConfig(Node node, String bridgeConnectorIdentifier, Map<String, String> config) {
215 // TODO Auto-generated method stub
220 public boolean removeBridgeConnectorConfig(Node node, String bridgeConnectorIdentifier, Map<String, String> config) {
221 // TODO Auto-generated method stub
226 public Map<String, String> getBridgeConnectorConfigs(Node node, String bridgeConnectorIdentifier) {
227 // TODO Auto-generated method stub
232 * Create a Port Attached to a Bridge
233 * Ex. ovs-vsctl add-port br0 vif0
234 * @param node Node serving this configuration service
235 * @param bridgeDomainIdentifier String representation of a Bridge Domain
236 * @param portIdentifier String representation of a user defined Port Name
239 @SuppressWarnings("unchecked")
240 public boolean addPort(Node node, String bridgeIdentifier, String portIdentifier) throws Throwable{
242 if (connectionService == null) {
243 logger.error("Couldn't refer to the ConnectionService");
246 Connection connection = connectionService.getConnection(node);
248 if (connection != null) {
249 String newBridge = "new_bridge";
250 String newInterface = "new_interface";
251 String newPort = "new_port";
252 String newSwitch = "new_switch";
254 Map<String, OVSBridge> existingBridges = OVSBridge.monitorBridge(connection);
256 OVSBridge bridge = existingBridges.get(bridgeIdentifier);
258 List<String> portUuidPair = new ArrayList<String>();
259 portUuidPair.add("named-uuid");
260 portUuidPair.add(newPort);
262 List<Object> mutation = new ArrayList<Object>();
263 mutation.add("ports");
264 mutation.add("insert");
265 mutation.add(portUuidPair);
266 List<Object> mutations = new ArrayList<Object>();
267 mutations.add(mutation);
269 List<String> bridgeUuidPair = new ArrayList<String>();
270 bridgeUuidPair.add("uuid");
271 bridgeUuidPair.add(bridge.getUuid());
273 List<Object> whereInner = new ArrayList<Object>();
274 whereInner.add("_uuid");
275 whereInner.add("==");
276 whereInner.add(bridgeUuidPair);
278 List<Object> where = new ArrayList<Object>();
279 where.add(whereInner);
281 MutateRequest mutateBridgeRequest = new MutateRequest("Bridge", where, mutations);
283 Map<String, Object> portRow = new HashMap<String, Object>();
284 portRow.put("name", portIdentifier);
285 ArrayList<String> interfaces = new ArrayList<String>();
286 interfaces.add("named-uuid");
287 interfaces.add(newInterface);
288 portRow.put("interfaces", interfaces);
289 InsertRequest addPortRequest = new InsertRequest("insert", "Port", newPort, portRow);
291 Map<String, Object> interfaceRow = new HashMap<String, Object>();
292 interfaceRow.put("name", portIdentifier);
293 InsertRequest addIntfRequest = new InsertRequest("insert", "Interface", newInterface, interfaceRow);
295 Object[] params = {"Open_vSwitch", mutateBridgeRequest, addIntfRequest, addPortRequest};
296 OvsdbMessage msg = new OvsdbMessage("transact", params);
298 connection.sendMessage(msg);
299 connection.readResponse(Uuid[].class);
308 * Create a Port with a VLAN Tag and it to a Bridge
309 * Ex. ovs-vsctl add-port br0 vxlan1 -- set interface vxlan1 type=vxlan options:remote_ip=192.168.1.11
310 * @param node Node serving this configuration service
311 * @param portIdentifier String representation of a user defined Port Name
312 * @param vlanid integer representing the VLAN Tag
315 @SuppressWarnings("unchecked")
316 public boolean addPortVlan(Node node, String bridgeIdentifier, String portIdentifier, int vlanid) throws Throwable{
318 if (connectionService == null) {
319 logger.error("Couldn't refer to the ConnectionService");
322 Connection connection = connectionService.getConnection(node);
324 if (connection != null) {
325 String newBridge = "new_bridge";
326 String newInterface = "new_interface";
327 String newPort = "new_port";
328 String newSwitch = "new_switch";
330 Map<String, OVSBridge> existingBridges = OVSBridge.monitorBridge(connection);
332 OVSBridge bridge = existingBridges.get(bridgeIdentifier);
334 List<String> portUuidPair = new ArrayList<String>();
335 portUuidPair.add("named-uuid");
336 portUuidPair.add(newPort);
338 List<Object> mutation = new ArrayList<Object>();
339 mutation.add("ports");
340 mutation.add("insert");
341 mutation.add(portUuidPair);
342 List<Object> mutations = new ArrayList<Object>();
343 mutations.add(mutation);
345 List<String> bridgeUuidPair = new ArrayList<String>();
346 bridgeUuidPair.add("uuid");
347 bridgeUuidPair.add(bridge.getUuid());
349 List<Object> whereInner = new ArrayList<Object>();
350 whereInner.add("_uuid");
351 whereInner.add("==");
352 whereInner.add(bridgeUuidPair);
354 List<Object> where = new ArrayList<Object>();
355 where.add(whereInner);
357 MutateRequest mutateBridgeRequest = new MutateRequest("Bridge", where, mutations);
359 Map<String, Object> portRow = new HashMap<String, Object>();
360 portRow.put("name", portIdentifier);
361 portRow.put("tag", vlanid);
362 ArrayList<String> interfaces = new ArrayList<String>();
363 interfaces.add("named-uuid");
364 interfaces.add(newInterface);
365 portRow.put("interfaces", interfaces);
366 InsertRequest addPortRequest = new InsertRequest("insert", "Port", newPort, portRow);
368 Map<String, Object> interfaceRow = new HashMap<String, Object>();
369 interfaceRow.put("name", portIdentifier);
370 InsertRequest addIntfRequest = new InsertRequest("insert", "Interface", newInterface, interfaceRow);
372 Object[] params = {"Open_vSwitch", mutateBridgeRequest, addIntfRequest, addPortRequest};
373 OvsdbMessage msg = new OvsdbMessage("transact", params);
375 connection.sendMessage(msg);
376 connection.readResponse(Uuid[].class);
385 * Create an Encapsulated Tunnel Interface and destination Tunnel Endpoint
386 * Ex. ovs-vsctl add-port br0 vxlan1 -- set interface vxlan1 type=vxlan options:remote_ip=192.168.1.11
387 * @param node Node serving this configuration service
388 * @param bridgeDomainIdentifier String representation of a Bridge Domain
389 * @param portIdentifier String representation of a user defined Port Name
390 * @param tunnelendpoint IP address of the destination Tunnel Endpoint
391 * @param tunencap is the tunnel encapsulation options being CAPWAP, GRE or VXLAN
392 * The Bridge must already be defined before calling addTunnel.
395 @SuppressWarnings("unchecked")
396 public boolean addTunnel(Node node, String bridgeIdentifier,
397 String portidentifier, String tunnelendpoint, String tunencap)
400 if (connectionService == null) {
401 logger.error("Couldn't refer to the ConnectionService");
404 Connection connection = connectionService.getConnection(node);
406 if (connection != null) {
407 String newBridge = "new_bridge";
408 String newInterface = "new_interface";
409 String newPort = "new_port";
410 String newSwitch = "new_switch";
412 Map<String, OVSBridge> existingBridges = OVSBridge.monitorBridge(connection);
414 OVSBridge bridge = existingBridges.get(bridgeIdentifier);
416 List<String> portUuidPair = new ArrayList<String>();
417 portUuidPair.add("named-uuid");
418 portUuidPair.add(newPort);
420 List<Object> mutation = new ArrayList<Object>();
421 mutation.add("ports");
422 mutation.add("insert");
423 mutation.add(portUuidPair);
424 List<Object> mutations = new ArrayList<Object>();
425 mutations.add(mutation);
427 List<String> bridgeUuidPair = new ArrayList<String>();
428 bridgeUuidPair.add("uuid");
429 bridgeUuidPair.add(bridge.getUuid());
431 List<Object> whereInner = new ArrayList<Object>();
432 whereInner.add("_uuid");
433 whereInner.add("==");
434 whereInner.add(bridgeUuidPair);
436 List<Object> where = new ArrayList<Object>();
437 where.add(whereInner);
439 MutateRequest mutateBridgeRequest = new MutateRequest("Bridge", where, mutations);
441 Map<String, Object> portRow = new HashMap<String, Object>();
442 portRow.put("name", portidentifier);
443 ArrayList<String> interfaces = new ArrayList<String>();
444 interfaces.add("named-uuid");
445 interfaces.add(newInterface);
446 portRow.put("interfaces", interfaces);
447 InsertRequest addPortRequest = new InsertRequest("insert", "Port", newPort, portRow);
449 Map<String, Object> interfaceRow = new HashMap<String, Object>();
450 interfaceRow.put("name", portidentifier);
451 interfaceRow.put("type", tunencap);
452 ArrayList<Object> intopt = new ArrayList<Object>();
453 interfaceRow.put("options", intopt);
454 ArrayList<Object> intoptmap = new ArrayList<Object>();
455 ArrayList<String> intoptep = new ArrayList<String>();
457 intopt.add(intoptmap);
458 intoptmap.add(intoptep);
459 intoptep.add("remote_ip");
460 intoptep.add(tunnelendpoint);
462 InsertRequest addIntfRequest = new InsertRequest("insert", "Interface",
463 newInterface, interfaceRow);
465 Object[] params = {"Open_vSwitch", mutateBridgeRequest, addIntfRequest, addPortRequest};
466 OvsdbMessage msg = new OvsdbMessage("transact", params);
468 connection.sendMessage(msg);
469 connection.readResponse(Uuid[].class);
478 public Object genericConfigurationEvent(Node node, Map<String, String> config) {
479 // TODO Auto-generated method stub