CNlucius
Committed by Gerrit Code Review

ONOS-2708

Add implementation of getting ovsdb ports or bridges in the ovsdb node.

Change-Id: If31af08ccb90a29bc800a79f332dae2bc497b105
1 -/* 1 +/*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015 Open Networking Laboratory
3 - * 3 + *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); 4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License. 5 + * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at 6 + * You may obtain a copy of the License at
7 - * 7 + *
8 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
9 - * 9 + *
10 - * Unless required by applicable law or agreed to in writing, software 10 + * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, 11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and 13 + * See the License for the specific language governing permissions and
14 - * limitations under the License. 14 + * limitations under the License.
15 - */ 15 + */
16 -package org.onosproject.net.behaviour; 16 +package org.onosproject.net.behaviour;
17 - 17 +
18 -import java.util.Collection; 18 +import java.util.Collection;
19 - 19 +import java.util.Set;
20 -import org.onosproject.net.device.PortDescription; 20 +
21 -import org.onosproject.net.driver.HandlerBehaviour; 21 +import org.onosproject.net.PortNumber;
22 - 22 +import org.onosproject.net.device.PortDescription;
23 -/** 23 +import org.onosproject.net.driver.HandlerBehaviour;
24 - * Behaviour for handling various drivers for bridge configurations. 24 +
25 - */ 25 +/**
26 -public interface BridgeConfig extends HandlerBehaviour { 26 + * Behaviour for handling various drivers for bridge configurations.
27 - 27 + */
28 - /** 28 +public interface BridgeConfig extends HandlerBehaviour {
29 - * Add a bridge. 29 +
30 - * 30 + /**
31 - * @param bridgeName bridge name 31 + * Add a bridge.
32 - */ 32 + *
33 - void addBridge(BridgeName bridgeName); 33 + * @param bridgeName bridge name
34 - 34 + */
35 - /** 35 + void addBridge(BridgeName bridgeName);
36 - * Remove a bridge. 36 +
37 - * 37 + /**
38 - * @param bridgeName bridge name 38 + * Remove a bridge.
39 - */ 39 + *
40 - void deleteBridge(BridgeName bridgeName); 40 + * @param bridgeName bridge name
41 - 41 + */
42 - /** 42 + void deleteBridge(BridgeName bridgeName);
43 - * Remove a bridge. 43 +
44 - * 44 + /**
45 - * @return bridge collection 45 + * Remove a bridge.
46 - */ 46 + *
47 - Collection<BridgeDescription> getBridges(); 47 + * @return bridge collection
48 - 48 + */
49 - /** 49 + Collection<BridgeDescription> getBridges();
50 - * Add a logical/virtual port. 50 +
51 - * 51 + /**
52 - * @param port port number 52 + * Add a logical/virtual port.
53 - */ 53 + *
54 - void addPort(PortDescription port); 54 + * @param port port number
55 - 55 + */
56 - /** 56 + void addPort(PortDescription port);
57 - * Delete a logical/virtual port. 57 +
58 - * 58 + /**
59 - * @param port port number 59 + * Delete a logical/virtual port.
60 - */ 60 + *
61 - void deletePort(PortDescription port); 61 + * @param port port number
62 - 62 + */
63 - /** 63 + void deletePort(PortDescription port);
64 - * Delete a logical/virtual port. 64 +
65 - * 65 + /**
66 - * @return collection of port 66 + * Delete a logical/virtual port.
67 - */ 67 + *
68 - Collection<PortDescription> getPorts(); 68 + * @return collection of port
69 -} 69 + */
70 + Collection<PortDescription> getPorts();
71 +
72 + /**
73 + * Get a collection of port.
74 + *
75 + * @return portNumbers set of PortNumber
76 + */
77 + Set<PortNumber> getPortNumbers();
78 +}
......
1 -/* 1 +/*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015 Open Networking Laboratory
3 - * 3 + *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); 4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License. 5 + * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at 6 + * You may obtain a copy of the License at
7 - * 7 + *
8 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
9 - * 9 + *
10 - * Unless required by applicable law or agreed to in writing, software 10 + * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, 11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and 13 + * See the License for the specific language governing permissions and
14 - * limitations under the License. 14 + * limitations under the License.
15 - */ 15 + */
16 -package org.onosproject.driver.ovsdb; 16 +package org.onosproject.driver.ovsdb;
17 - 17 +
18 -import java.util.Collection; 18 +import java.util.Collection;
19 -import java.util.Set; 19 +import java.util.Collections;
20 - 20 +import java.util.HashSet;
21 -import org.onlab.packet.IpAddress; 21 +import java.util.Set;
22 -import org.onosproject.net.DeviceId; 22 +
23 -import org.onosproject.net.PortNumber; 23 +import org.onlab.packet.IpAddress;
24 -import org.onosproject.net.behaviour.BridgeConfig; 24 +import org.onosproject.net.DeviceId;
25 -import org.onosproject.net.behaviour.BridgeDescription; 25 +import org.onosproject.net.PortNumber;
26 -import org.onosproject.net.behaviour.BridgeName; 26 +import org.onosproject.net.behaviour.BridgeConfig;
27 -import org.onosproject.net.behaviour.DefaultBridgeDescription; 27 +import org.onosproject.net.behaviour.BridgeDescription;
28 -import org.onosproject.net.device.DefaultPortDescription; 28 +import org.onosproject.net.behaviour.BridgeName;
29 -import org.onosproject.net.device.PortDescription; 29 +import org.onosproject.net.behaviour.DefaultBridgeDescription;
30 -import org.onosproject.net.driver.AbstractHandlerBehaviour; 30 +import org.onosproject.net.device.DefaultPortDescription;
31 -import org.onosproject.net.driver.DriverHandler; 31 +import org.onosproject.net.device.PortDescription;
32 -import org.onosproject.ovsdb.controller.OvsdbBridge; 32 +import org.onosproject.net.driver.AbstractHandlerBehaviour;
33 -import org.onosproject.ovsdb.controller.OvsdbClientService; 33 +import org.onosproject.net.driver.DriverHandler;
34 -import org.onosproject.ovsdb.controller.OvsdbController; 34 +import org.onosproject.ovsdb.controller.OvsdbBridge;
35 -import org.onosproject.ovsdb.controller.OvsdbNodeId; 35 +import org.onosproject.ovsdb.controller.OvsdbClientService;
36 -import org.onosproject.ovsdb.controller.OvsdbPort; 36 +import org.onosproject.ovsdb.controller.OvsdbController;
37 - 37 +import org.onosproject.ovsdb.controller.OvsdbNodeId;
38 -import com.google.common.collect.Sets; 38 +import org.onosproject.ovsdb.controller.OvsdbPort;
39 - 39 +
40 -/** 40 +import com.google.common.collect.Sets;
41 - * The implementation of BridageConfig. 41 +
42 - */ 42 +/**
43 -public class OvsdbBridgeConfig extends AbstractHandlerBehaviour 43 + * The implementation of BridageConfig.
44 - implements BridgeConfig { 44 + */
45 - 45 +public class OvsdbBridgeConfig extends AbstractHandlerBehaviour
46 - @Override 46 + implements BridgeConfig {
47 - public void addBridge(BridgeName bridgeName) { 47 +
48 - DriverHandler handler = handler(); 48 + @Override
49 - OvsdbClientService ovsdbNode = getOvsdbNode(handler); 49 + public void addBridge(BridgeName bridgeName) {
50 - ovsdbNode.createBridge(bridgeName.name()); 50 + DriverHandler handler = handler();
51 - } 51 + OvsdbClientService clientService = getOvsdbClientService(handler);
52 - 52 + clientService.createBridge(bridgeName.name());
53 - @Override 53 + }
54 - public void deleteBridge(BridgeName bridgeName) { 54 +
55 - DriverHandler handler = handler(); 55 + @Override
56 - OvsdbClientService ovsdbNode = getOvsdbNode(handler); 56 + public void deleteBridge(BridgeName bridgeName) {
57 - ovsdbNode.dropBridge(bridgeName.name()); 57 + DriverHandler handler = handler();
58 - } 58 + OvsdbClientService clientService = getOvsdbClientService(handler);
59 - 59 + clientService.dropBridge(bridgeName.name());
60 - @Override 60 + }
61 - public Collection<BridgeDescription> getBridges() { 61 +
62 - DriverHandler handler = handler(); 62 + @Override
63 - DeviceId deviceId = handler.data().deviceId(); 63 + public Collection<BridgeDescription> getBridges() {
64 - OvsdbClientService ovsdbNode = getOvsdbNode(handler); 64 + DriverHandler handler = handler();
65 - Set<OvsdbBridge> ovsdbSet = ovsdbNode.getBridges(); 65 + DeviceId deviceId = handler.data().deviceId();
66 - Collection<BridgeDescription> bridges = Sets.newHashSet(); 66 + OvsdbClientService clientService = getOvsdbClientService(handler);
67 - ovsdbSet.forEach(o -> { 67 + Set<OvsdbBridge> ovsdbSet = clientService.getBridges();
68 - BridgeName bridgeName = BridgeName.bridgeName(o.bridgeName() 68 + Collection<BridgeDescription> bridges = Sets.newHashSet();
69 - .toString()); 69 + ovsdbSet.forEach(o -> {
70 - DeviceId ownDeviceId = DeviceId.deviceId(o.datapathId().toString()); 70 + BridgeName bridgeName = BridgeName
71 - BridgeDescription description = new DefaultBridgeDescription( 71 + .bridgeName(o.bridgeName().value());
72 - bridgeName, 72 + DeviceId ownDeviceId = DeviceId.deviceId("of:" + o.datapathId().value());
73 - deviceId, 73 + BridgeDescription description = new DefaultBridgeDescription(bridgeName,
74 - ownDeviceId); 74 + deviceId,
75 - bridges.add(description); 75 + ownDeviceId);
76 - }); 76 + bridges.add(description);
77 - return bridges; 77 + });
78 - } 78 + return bridges == null ? Collections.emptySet() : bridges;
79 - 79 + }
80 - @Override 80 +
81 - public void addPort(PortDescription port) { 81 + @Override
82 - DriverHandler handler = handler(); 82 + public void addPort(PortDescription port) {
83 - OvsdbClientService ovsdbNode = getOvsdbNode(handler); 83 + DriverHandler handler = handler();
84 - Set<OvsdbBridge> ovsdbSet = ovsdbNode.getBridges(); 84 + OvsdbClientService clientService = getOvsdbClientService(handler);
85 - if (ovsdbSet != null && ovsdbSet.size() > 0) { 85 + Set<OvsdbBridge> ovsdbSet = clientService.getBridges();
86 - OvsdbBridge bridge = ovsdbSet.iterator().next(); 86 + if (ovsdbSet != null && ovsdbSet.size() > 0) {
87 - ovsdbNode.createPort(bridge.bridgeName().toString(), port 87 + OvsdbBridge bridge = ovsdbSet.iterator().next();
88 - .portNumber().toString()); 88 + clientService.createPort(bridge.bridgeName().toString(), port
89 - } 89 + .portNumber().toString());
90 - } 90 + }
91 - 91 + }
92 - @Override 92 +
93 - public void deletePort(PortDescription port) { 93 + @Override
94 - DriverHandler handler = handler(); 94 + public void deletePort(PortDescription port) {
95 - OvsdbClientService ovsdbNode = getOvsdbNode(handler); 95 + DriverHandler handler = handler();
96 - Set<OvsdbBridge> ovsdbSet = ovsdbNode.getBridges(); 96 + OvsdbClientService clientService = getOvsdbClientService(handler);
97 - if (ovsdbSet != null && ovsdbSet.size() > 0) { 97 + Set<OvsdbBridge> ovsdbSet = clientService.getBridges();
98 - OvsdbBridge bridge = ovsdbSet.iterator().next(); 98 + if (ovsdbSet != null && ovsdbSet.size() > 0) {
99 - ovsdbNode.dropPort(bridge.bridgeName().toString(), port 99 + OvsdbBridge bridge = ovsdbSet.iterator().next();
100 - .portNumber().toString()); 100 + clientService.dropPort(bridge.bridgeName().toString(), port
101 - } 101 + .portNumber().toString());
102 - } 102 + }
103 - 103 + }
104 - @Override 104 +
105 - public Collection<PortDescription> getPorts() { 105 + @Override
106 - DriverHandler handler = handler(); 106 + public Collection<PortDescription> getPorts() {
107 - OvsdbClientService ovsdbNode = getOvsdbNode(handler); 107 + DriverHandler handler = handler();
108 - Set<OvsdbPort> ovsdbSet = ovsdbNode.getPorts(); 108 + OvsdbClientService clientService = getOvsdbClientService(handler);
109 - Collection<PortDescription> ports = Sets.newHashSet(); 109 + Set<OvsdbPort> ovsdbSet = clientService.getPorts();
110 - ovsdbSet.forEach(o -> { 110 + Collection<PortDescription> ports = Sets.newHashSet();
111 - PortNumber port = PortNumber.portNumber(o.portNumber().value()); 111 + ovsdbSet.forEach(o -> {
112 - PortDescription description = new DefaultPortDescription(port, true); 112 + PortNumber port = PortNumber.portNumber(o.portNumber().value());
113 - ports.add(description); 113 + PortDescription description = new DefaultPortDescription(port, true);
114 - }); 114 + ports.add(description);
115 - return ports; 115 + });
116 - } 116 + return ports;
117 - 117 + }
118 - // OvsdbNodeId(IP:port) is used in the adaptor while DeviceId(ovsdb:IP:port) 118 +
119 - // is used in the core. So DeviceId need be changed to OvsdbNodeId. 119 + // OvsdbNodeId(IP:port) is used in the adaptor while DeviceId(ovsdb:IP:port)
120 - private OvsdbNodeId changeDeviceIdToNodeId(DeviceId deviceId) { 120 + // is used in the core. So DeviceId need be changed to OvsdbNodeId.
121 - int lastColon = deviceId.toString().lastIndexOf(":"); 121 + private OvsdbNodeId changeDeviceIdToNodeId(DeviceId deviceId) {
122 - int fistColon = deviceId.toString().indexOf(":"); 122 + int lastColon = deviceId.toString().lastIndexOf(":");
123 - String ip = deviceId.toString().substring(fistColon + 1, lastColon); 123 + int fistColon = deviceId.toString().indexOf(":");
124 - String port = deviceId.toString().substring(lastColon + 1); 124 + String ip = deviceId.toString().substring(fistColon + 1, lastColon);
125 - IpAddress ipAddress = IpAddress.valueOf(ip); 125 + String port = deviceId.toString().substring(lastColon + 1);
126 - long portL = Long.valueOf(port).longValue(); 126 + IpAddress ipAddress = IpAddress.valueOf(ip);
127 - return new OvsdbNodeId(ipAddress, portL); 127 + long portL = Long.valueOf(port).longValue();
128 - } 128 + return new OvsdbNodeId(ipAddress, portL);
129 - 129 + }
130 - private OvsdbClientService getOvsdbNode(DriverHandler handler) { 130 +
131 - OvsdbController ovsController = handler.get(OvsdbController.class); 131 + // Used for getting OvsdbClientService.
132 - DeviceId deviceId = handler.data().deviceId(); 132 + private OvsdbClientService getOvsdbClientService(DriverHandler handler) {
133 - OvsdbNodeId nodeId = changeDeviceIdToNodeId(deviceId); 133 + OvsdbController ovsController = handler.get(OvsdbController.class);
134 - return ovsController.getOvsdbClient(nodeId); 134 + DeviceId deviceId = handler.data().deviceId();
135 - } 135 + OvsdbNodeId nodeId = changeDeviceIdToNodeId(deviceId);
136 -} 136 + return ovsController.getOvsdbClient(nodeId);
137 + }
138 +
139 + @Override
140 + public Set<PortNumber> getPortNumbers() {
141 + Set<PortNumber> ports = new HashSet<>();
142 + DriverHandler handler = handler();
143 + OvsdbClientService clientService = getOvsdbClientService(handler);
144 + Set<OvsdbPort> ovsdbSet = clientService.getPorts();
145 + ovsdbSet.forEach(o -> {
146 + PortNumber port = PortNumber.portNumber(o.portNumber().value(),
147 + o.portName().value());
148 + ports.add(port);
149 + });
150 + return ports;
151 + }
152 +}
......
1 -<?xml version="1.0" encoding="UTF-8"?> 1 +<?xml version="1.0" encoding="UTF-8"?>
2 -<!-- 2 +<!--
3 - ~ Copyright 2015 Open Networking Laboratory 3 + ~ Copyright 2015 Open Networking Laboratory
4 - ~ 4 + ~
5 - ~ Licensed under the Apache License, Version 2.0 (the "License"); 5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 - ~ you may not use this file except in compliance with the License. 6 + ~ you may not use this file except in compliance with the License.
7 - ~ You may obtain a copy of the License at 7 + ~ You may obtain a copy of the License at
8 - ~ 8 + ~
9 - ~ http://www.apache.org/licenses/LICENSE-2.0 9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 - ~ 10 + ~
11 - ~ Unless required by applicable law or agreed to in writing, software 11 + ~ Unless required by applicable law or agreed to in writing, software
12 - ~ distributed under the License is distributed on an "AS IS" BASIS, 12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 - ~ See the License for the specific language governing permissions and 14 + ~ See the License for the specific language governing permissions and
15 - ~ limitations under the License. 15 + ~ limitations under the License.
16 - --> 16 + -->
17 -<drivers> 17 +<drivers>
18 - <driver name="default" 18 + <driver name="default"
19 - manufacturer="ON.Lab" hwVersion="0.0.1" swVersion="0.0.1"> 19 + manufacturer="ON.Lab" hwVersion="0.0.1" swVersion="0.0.1">
20 - <behaviour api="org.onosproject.net.behaviour.Pipeliner" 20 + <behaviour api="org.onosproject.net.behaviour.Pipeliner"
21 - impl="org.onosproject.driver.pipeline.DefaultSingleTablePipeline"/> 21 + impl="org.onosproject.driver.pipeline.OpenVSwitchPipeline"/>
22 - <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" 22 + <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver"
23 - impl="org.onosproject.driver.handshaker.DefaultSwitchHandshaker"/> 23 + impl="org.onosproject.driver.handshaker.DefaultSwitchHandshaker"/>
24 - </driver> 24 + <behaviour api="org.onosproject.net.behaviour.TunnelConfig"
25 - <driver name="ovs" extends="default" 25 + impl="org.onosproject.driver.ovsdb.OvsdbTunnelConfig"/>
26 - manufacturer="Nicira, Inc\." hwVersion="Open vSwitch" swVersion="2\..*"> 26 + <behaviour api="org.onosproject.net.behaviour.BridgeConfig"
27 - <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" 27 + impl="org.onosproject.driver.ovsdb.OvsdbBridgeConfig"/>
28 - impl="org.onosproject.driver.handshaker.NiciraSwitchHandshaker"/> 28 + </driver>
29 - <behaviour api="org.onosproject.net.behaviour.TunnelConfig" 29 + <driver name="ovs" extends="default"
30 - impl="org.onosproject.driver.ovsdb.OvsdbTunnelConfig"/> 30 + manufacturer="Nicira, Inc\." hwVersion="Open vSwitch" swVersion="2\..*">
31 - <behaviour api="org.onosproject.net.behaviour.BridgeConfig" 31 + <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver"
32 - impl="org.onosproject.driver.ovsdb.OvsdbBridgeConfig"/> 32 + impl="org.onosproject.driver.handshaker.NiciraSwitchHandshaker"/>
33 - </driver> 33 + </driver>
34 - <driver name="ovs-corsa" extends="ovs" 34 + <driver name="ovs-corsa" extends="ovs"
35 - manufacturer="Corsa" hwVersion="emulation" swVersion="0.0.0"> 35 + manufacturer="Corsa" hwVersion="emulation" swVersion="0.0.0">
36 - <behaviour api="org.onosproject.net.behaviour.Pipeliner" 36 + <behaviour api="org.onosproject.net.behaviour.Pipeliner"
37 - impl="org.onosproject.driver.pipeline.OVSCorsaPipeline"/> 37 + impl="org.onosproject.driver.pipeline.OVSCorsaPipeline"/>
38 - </driver> 38 + </driver>
39 - <driver name="spring-open-cpqd" extends="default" 39 + <driver name="spring-open-cpqd" extends="default"
40 - manufacturer="Stanford University, Ericsson Research and CPqD Research" 40 + manufacturer="Stanford University, Ericsson Research and CPqD Research"
41 - hwVersion="OpenFlow 1.3 Reference Userspace Switch" swVersion=".*"> 41 + hwVersion="OpenFlow 1.3 Reference Userspace Switch" swVersion=".*">
42 - <behaviour api="org.onosproject.net.behaviour.Pipeliner" 42 + <behaviour api="org.onosproject.net.behaviour.Pipeliner"
43 - impl="org.onosproject.driver.pipeline.SpringOpenTTP"/> 43 + impl="org.onosproject.driver.pipeline.SpringOpenTTP"/>
44 - </driver> 44 + </driver>
45 - <driver name="spring-open" extends="default" 45 + <driver name="spring-open" extends="default"
46 - manufacturer="Dell " hwVersion="OpenFlow switch HW ver. 1.0" 46 + manufacturer="Dell " hwVersion="OpenFlow switch HW ver. 1.0"
47 - swVersion="OpenFlow switch SW ver. 1.0 and 1.3"> 47 + swVersion="OpenFlow switch SW ver. 1.0 and 1.3">
48 - <behaviour api="org.onosproject.net.behaviour.Pipeliner" 48 + <behaviour api="org.onosproject.net.behaviour.Pipeliner"
49 - impl="org.onosproject.driver.pipeline.SpringOpenTTPDell"/> 49 + impl="org.onosproject.driver.pipeline.SpringOpenTTPDell"/>
50 - </driver> 50 + </driver>
51 - <driver name="linc-oe" extends="default" 51 + <driver name="linc-oe" extends="default"
52 - manufacturer="FlowForwarding.org" hwVersion="Unknown" 52 + manufacturer="FlowForwarding.org" hwVersion="Unknown"
53 - swVersion="LINC-OE OpenFlow Software Switch 1.1"> 53 + swVersion="LINC-OE OpenFlow Software Switch 1.1">
54 - <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" 54 + <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver"
55 - impl="org.onosproject.driver.handshaker.OFOpticalSwitchImplLINC13"/> 55 + impl="org.onosproject.driver.handshaker.OFOpticalSwitchImplLINC13"/>
56 - </driver> 56 + </driver>
57 - <driver name="corsa" 57 + <driver name="corsa"
58 - manufacturer="Corsa" hwVersion="Corsa Element" swVersion="2.3.1"> 58 + manufacturer="Corsa" hwVersion="Corsa Element" swVersion="2.3.1">
59 - <behaviour api="org.onosproject.net.behaviour.Pipeliner" 59 + <behaviour api="org.onosproject.net.behaviour.Pipeliner"
60 - impl="org.onosproject.driver.pipeline.CorsaPipeline"/> 60 + impl="org.onosproject.driver.pipeline.CorsaPipeline"/>
61 - <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" 61 + <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver"
62 - impl="org.onosproject.driver.handshaker.CorsaSwitchHandshaker"/> 62 + impl="org.onosproject.driver.handshaker.CorsaSwitchHandshaker"/>
63 - </driver> 63 + </driver>
64 - <driver name="ofdpa" extends="default" 64 + <driver name="ofdpa" extends="default"
65 - manufacturer="Broadcom Corp." hwVersion="OF-DPA.*" swVersion="OF-DPA.*"> 65 + manufacturer="Broadcom Corp." hwVersion="OF-DPA.*" swVersion="OF-DPA.*">
66 - <behaviour api="org.onosproject.net.behaviour.Pipeliner" 66 + <behaviour api="org.onosproject.net.behaviour.Pipeliner"
67 - impl="org.onosproject.driver.pipeline.OFDPA1Pipeline"/> 67 + impl="org.onosproject.driver.pipeline.OFDPA1Pipeline"/>
68 - </driver> 68 + </driver>
69 - <driver name="pmc-olt" extends="default" 69 + <driver name="pmc-olt" extends="default"
70 - manufacturer="Big Switch Networks" hwVersion="ivs 0.5" swVersion="ivs 0.5"> 70 + manufacturer="Big Switch Networks" hwVersion="ivs 0.5" swVersion="ivs 0.5">
71 - <behaviour api="org.onosproject.net.behaviour.Pipeliner" 71 + <behaviour api="org.onosproject.net.behaviour.Pipeliner"
72 - impl="org.onosproject.driver.pipeline.OLTPipeline"/> 72 + impl="org.onosproject.driver.pipeline.OLTPipeline"/>
73 - </driver> 73 + </driver>
74 - <driver name="g.fast" extends="default" 74 + <driver name="g.fast" extends="default"
75 - manufacturer="TEST1" hwVersion="TEST2" swVersion="TEST3"> 75 + manufacturer="TEST1" hwVersion="TEST2" swVersion="TEST3">
76 - <behaviour api="org.onosproject.net.behaviour.Pipeliner" 76 + <behaviour api="org.onosproject.net.behaviour.Pipeliner"
77 - impl="org.onosproject.driver.pipeline.OLTPipeline"/> 77 + impl="org.onosproject.driver.pipeline.OLTPipeline"/>
78 - </driver> 78 + </driver>
79 - <!-- The SoftRouter driver is meant to be used by any software/NPU based 79 + <!-- The SoftRouter driver is meant to be used by any software/NPU based
80 - ~ switch that wishes to implement a simple 2-table router. To use this 80 + ~ switch that wishes to implement a simple 2-table router. To use this
81 - ~ driver, configure ONOS with the dpid of the device, or extend the 81 + ~ driver, configure ONOS with the dpid of the device, or extend the
82 - ~ driver declaration with the manufacturer/hwVersion/swVersion of the 82 + ~ driver declaration with the manufacturer/hwVersion/swVersion of the
83 - ~ device (see 'noviflow' example). 83 + ~ device (see 'noviflow' example).
84 - --> 84 + -->
85 - <driver name="softrouter" extends="default" 85 + <driver name="softrouter" extends="default"
86 - manufacturer="Various" hwVersion="various" swVersion="0.0.0"> 86 + manufacturer="Various" hwVersion="various" swVersion="0.0.0">
87 - <behaviour api="org.onosproject.net.behaviour.Pipeliner" 87 + <behaviour api="org.onosproject.net.behaviour.Pipeliner"
88 - impl="org.onosproject.driver.pipeline.SoftRouterPipeline"/> 88 + impl="org.onosproject.driver.pipeline.SoftRouterPipeline"/>
89 - </driver> 89 + </driver>
90 - <driver name="centec-V350" extends="default" 90 + <driver name="centec-V350" extends="default"
91 - manufacturer=".*Centec.*" hwVersion=".*" swVersion="3.1.*"> 91 + manufacturer=".*Centec.*" hwVersion=".*" swVersion="3.1.*">
92 - <behaviour api="org.onosproject.net.behaviour.Pipeliner" 92 + <behaviour api="org.onosproject.net.behaviour.Pipeliner"
93 - impl="org.onosproject.driver.pipeline.CentecV350Pipeline"/> 93 + impl="org.onosproject.driver.pipeline.CentecV350Pipeline"/>
94 - </driver> 94 + </driver>
95 - <driver name="pica" extends="default" 95 + <driver name="pica" extends="default"
96 - manufacturer="Pica8, Inc." hwVersion=".*" swVersion="PicOS 2.6"> 96 + manufacturer="Pica8, Inc." hwVersion=".*" swVersion="PicOS 2.6">
97 - <behaviour api="org.onosproject.net.behaviour.Pipeliner" 97 + <behaviour api="org.onosproject.net.behaviour.Pipeliner"
98 - impl="org.onosproject.driver.pipeline.PicaPipeline"/> 98 + impl="org.onosproject.driver.pipeline.PicaPipeline"/>
99 - </driver> 99 + </driver>
100 - <driver name="noviflow" extends="softrouter" 100 + <driver name="noviflow" extends="softrouter"
101 - manufacturer="NoviFlow Inc" hwVersion="NS.*" swVersion="NW.*"> 101 + manufacturer="NoviFlow Inc" hwVersion="NS.*" swVersion="NW.*">
102 - </driver> 102 + </driver>
103 - <!-- Emulation of the ofdpa pipeline using a CPqD OF 1.3 software switch. 103 + <!-- Emulation of the ofdpa pipeline using a CPqD OF 1.3 software switch.
104 - ~ To use this driver, configure ONOS with the dpid of the device. 104 + ~ To use this driver, configure ONOS with the dpid of the device.
105 - --> 105 + -->
106 - <driver name="ofdpa-cpqd" extends="default" 106 + <driver name="ofdpa-cpqd" extends="default"
107 - manufacturer="ONF" 107 + manufacturer="ONF"
108 - hwVersion="OF1.3 Software Switch from CPqD" swVersion="for Group Chaining"> 108 + hwVersion="OF1.3 Software Switch from CPqD" swVersion="for Group Chaining">
109 - <behaviour api="org.onosproject.net.behaviour.Pipeliner" 109 + <behaviour api="org.onosproject.net.behaviour.Pipeliner"
110 - impl="org.onosproject.driver.pipeline.CpqdOFDPA1Pipeline"/> 110 + impl="org.onosproject.driver.pipeline.CpqdOFDPA1Pipeline"/>
111 - </driver> 111 + </driver>
112 - <driver name="calient" extends="default" 112 + <driver name="calient" extends="default"
113 - manufacturer="calient inc" hwVersion="calient hardware" 113 + manufacturer="calient inc" hwVersion="calient hardware"
114 - swVersion="ocs switch"> 114 + swVersion="ocs switch">
115 - <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" 115 + <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver"
116 - impl="org.onosproject.driver.handshaker.CalientFiberSwitchHandshaker"/> 116 + impl="org.onosproject.driver.handshaker.CalientFiberSwitchHandshaker"/>
117 - </driver> 117 + </driver>
118 -</drivers> 118 +</drivers>
119 - 119 +
......
1 -/* 1 +/*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015 Open Networking Laboratory
3 - * 3 + *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); 4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License. 5 + * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at 6 + * You may obtain a copy of the License at
7 - * 7 + *
8 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
9 - * 9 + *
10 - * Unless required by applicable law or agreed to in writing, software 10 + * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, 11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and 13 + * See the License for the specific language governing permissions and
14 - * limitations under the License. 14 + * limitations under the License.
15 - */ 15 + */
16 -package org.onosproject.ovsdb.controller.driver; 16 +package org.onosproject.ovsdb.controller.driver;
17 - 17 +
18 -import io.netty.channel.Channel; 18 +import io.netty.channel.Channel;
19 - 19 +
20 -import java.net.InetSocketAddress; 20 +import java.net.InetSocketAddress;
21 -import java.util.ArrayList; 21 +import java.util.ArrayList;
22 -import java.util.HashSet; 22 +import java.util.HashSet;
23 -import java.util.List; 23 +import java.util.Iterator;
24 -import java.util.Map; 24 +import java.util.List;
25 -import java.util.Set; 25 +import java.util.Map;
26 -import java.util.concurrent.ConcurrentMap; 26 +import java.util.Set;
27 -import java.util.concurrent.ExecutionException; 27 +import java.util.concurrent.ConcurrentMap;
28 - 28 +import java.util.concurrent.ExecutionException;
29 -import org.onlab.packet.IpAddress; 29 +
30 -import org.onosproject.ovsdb.controller.OvsdbBridge; 30 +import org.onlab.packet.IpAddress;
31 -import org.onosproject.ovsdb.controller.OvsdbClientService; 31 +import org.onosproject.ovsdb.controller.OvsdbBridge;
32 -import org.onosproject.ovsdb.controller.OvsdbConstant; 32 +import org.onosproject.ovsdb.controller.OvsdbBridgeName;
33 -import org.onosproject.ovsdb.controller.OvsdbNodeId; 33 +import org.onosproject.ovsdb.controller.OvsdbClientService;
34 -import org.onosproject.ovsdb.controller.OvsdbPort; 34 +import org.onosproject.ovsdb.controller.OvsdbConstant;
35 -import org.onosproject.ovsdb.controller.OvsdbRowStore; 35 +import org.onosproject.ovsdb.controller.OvsdbDatapathId;
36 -import org.onosproject.ovsdb.controller.OvsdbStore; 36 +import org.onosproject.ovsdb.controller.OvsdbNodeId;
37 -import org.onosproject.ovsdb.controller.OvsdbTableStore; 37 +import org.onosproject.ovsdb.controller.OvsdbPort;
38 -import org.onosproject.ovsdb.controller.OvsdbTunnel; 38 +import org.onosproject.ovsdb.controller.OvsdbPortName;
39 -import org.onosproject.ovsdb.rfc.jsonrpc.Callback; 39 +import org.onosproject.ovsdb.controller.OvsdbPortNumber;
40 -import org.onosproject.ovsdb.rfc.message.OperationResult; 40 +import org.onosproject.ovsdb.controller.OvsdbRowStore;
41 -import org.onosproject.ovsdb.rfc.message.TableUpdates; 41 +import org.onosproject.ovsdb.controller.OvsdbStore;
42 -import org.onosproject.ovsdb.rfc.notation.Condition; 42 +import org.onosproject.ovsdb.controller.OvsdbTableStore;
43 -import org.onosproject.ovsdb.rfc.notation.Mutation; 43 +import org.onosproject.ovsdb.controller.OvsdbTunnel;
44 -import org.onosproject.ovsdb.rfc.notation.OvsdbSet; 44 +import org.onosproject.ovsdb.rfc.jsonrpc.Callback;
45 -import org.onosproject.ovsdb.rfc.notation.Row; 45 +import org.onosproject.ovsdb.rfc.message.OperationResult;
46 -import org.onosproject.ovsdb.rfc.notation.UUID; 46 +import org.onosproject.ovsdb.rfc.message.TableUpdates;
47 -import org.onosproject.ovsdb.rfc.operations.Delete; 47 +import org.onosproject.ovsdb.rfc.notation.Condition;
48 -import org.onosproject.ovsdb.rfc.operations.Insert; 48 +import org.onosproject.ovsdb.rfc.notation.Mutation;
49 -import org.onosproject.ovsdb.rfc.operations.Mutate; 49 +import org.onosproject.ovsdb.rfc.notation.OvsdbSet;
50 -import org.onosproject.ovsdb.rfc.operations.Operation; 50 +import org.onosproject.ovsdb.rfc.notation.Row;
51 -import org.onosproject.ovsdb.rfc.operations.Update; 51 +import org.onosproject.ovsdb.rfc.notation.UUID;
52 -import org.onosproject.ovsdb.rfc.schema.ColumnSchema; 52 +import org.onosproject.ovsdb.rfc.operations.Delete;
53 -import org.onosproject.ovsdb.rfc.schema.DatabaseSchema; 53 +import org.onosproject.ovsdb.rfc.operations.Insert;
54 -import org.onosproject.ovsdb.rfc.schema.TableSchema; 54 +import org.onosproject.ovsdb.rfc.operations.Mutate;
55 -import org.onosproject.ovsdb.rfc.table.Bridge; 55 +import org.onosproject.ovsdb.rfc.operations.Operation;
56 -import org.onosproject.ovsdb.rfc.table.Controller; 56 +import org.onosproject.ovsdb.rfc.operations.Update;
57 -import org.onosproject.ovsdb.rfc.table.Interface; 57 +import org.onosproject.ovsdb.rfc.schema.ColumnSchema;
58 -import org.onosproject.ovsdb.rfc.table.OvsdbTable; 58 +import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
59 -import org.onosproject.ovsdb.rfc.table.Port; 59 +import org.onosproject.ovsdb.rfc.schema.TableSchema;
60 -import org.onosproject.ovsdb.rfc.table.TableGenerator; 60 +import org.onosproject.ovsdb.rfc.table.Bridge;
61 -import org.onosproject.ovsdb.rfc.utils.ConditionUtil; 61 +import org.onosproject.ovsdb.rfc.table.Controller;
62 -import org.onosproject.ovsdb.rfc.utils.FromJsonUtil; 62 +import org.onosproject.ovsdb.rfc.table.Interface;
63 -import org.onosproject.ovsdb.rfc.utils.JsonRpcWriterUtil; 63 +import org.onosproject.ovsdb.rfc.table.OvsdbTable;
64 -import org.onosproject.ovsdb.rfc.utils.MutationUtil; 64 +import org.onosproject.ovsdb.rfc.table.Port;
65 -import org.slf4j.Logger; 65 +import org.onosproject.ovsdb.rfc.table.TableGenerator;
66 -import org.slf4j.LoggerFactory; 66 +import org.onosproject.ovsdb.rfc.utils.ConditionUtil;
67 - 67 +import org.onosproject.ovsdb.rfc.utils.FromJsonUtil;
68 -import com.fasterxml.jackson.databind.JsonNode; 68 +import org.onosproject.ovsdb.rfc.utils.JsonRpcWriterUtil;
69 -import com.google.common.base.Function; 69 +import org.onosproject.ovsdb.rfc.utils.MutationUtil;
70 -import com.google.common.collect.Lists; 70 +import org.slf4j.Logger;
71 -import com.google.common.collect.Maps; 71 +import org.slf4j.LoggerFactory;
72 -import com.google.common.util.concurrent.Futures; 72 +
73 -import com.google.common.util.concurrent.ListenableFuture; 73 +import com.fasterxml.jackson.databind.JsonNode;
74 -import com.google.common.util.concurrent.SettableFuture; 74 +import com.google.common.base.Function;
75 - 75 +import com.google.common.collect.Lists;
76 -/** 76 +import com.google.common.collect.Maps;
77 - * An representation of an ovsdb client. 77 +import com.google.common.util.concurrent.Futures;
78 - */ 78 +import com.google.common.util.concurrent.ListenableFuture;
79 -public class DefaultOvsdbClient 79 +import com.google.common.util.concurrent.SettableFuture;
80 - implements OvsdbProviderService, OvsdbClientService { 80 +
81 - 81 +/**
82 - private final Logger log = LoggerFactory 82 + * An representation of an ovsdb client.
83 - .getLogger(DefaultOvsdbClient.class); 83 + */
84 - 84 +public class DefaultOvsdbClient
85 - private Channel channel; 85 + implements OvsdbProviderService, OvsdbClientService {
86 - 86 +
87 - private OvsdbAgent agent; 87 + private final Logger log = LoggerFactory
88 - private boolean connected; 88 + .getLogger(DefaultOvsdbClient.class);
89 - private OvsdbNodeId nodeId; 89 +
90 - private Callback monitorCallBack; 90 + private Channel channel;
91 - 91 +
92 - private OvsdbStore ovsdbStore = new OvsdbStore(); 92 + private OvsdbAgent agent;
93 - 93 + private boolean connected;
94 - private final Map<String, String> requestMethod = Maps.newHashMap(); 94 + private OvsdbNodeId nodeId;
95 - private final Map<String, SettableFuture<? extends Object>> requestResult = Maps 95 + private Callback monitorCallBack;
96 - .newHashMap(); 96 +
97 - 97 + private OvsdbStore ovsdbStore = new OvsdbStore();
98 - private final Map<String, DatabaseSchema> schema = Maps.newHashMap(); 98 +
99 - private final Set<OvsdbPort> ovsdbPorts = new HashSet<OvsdbPort>(); 99 + private final Map<String, String> requestMethod = Maps.newHashMap();
100 - private final Set<OvsdbTunnel> ovsdbTunnels = new HashSet<OvsdbTunnel>(); 100 + private final Map<String, SettableFuture<? extends Object>> requestResult = Maps
101 - private final Set<OvsdbBridge> ovsdbBridges = new HashSet<OvsdbBridge>(); 101 + .newHashMap();
102 - 102 +
103 - /** 103 + private final Map<String, DatabaseSchema> schema = Maps.newHashMap();
104 - * Creates an OvsdbClient. 104 + private final Set<OvsdbTunnel> ovsdbTunnels = new HashSet<OvsdbTunnel>();
105 - * 105 +
106 - * @param nodeId ovsdb node id 106 + /**
107 - */ 107 + * Creates an OvsdbClient.
108 - public DefaultOvsdbClient(OvsdbNodeId nodeId) { 108 + *
109 - this.nodeId = nodeId; 109 + * @param nodeId ovsdb node id
110 - } 110 + */
111 - 111 + public DefaultOvsdbClient(OvsdbNodeId nodeId) {
112 - @Override 112 + this.nodeId = nodeId;
113 - public OvsdbNodeId nodeId() { 113 + }
114 - return nodeId; 114 +
115 - } 115 + @Override
116 - 116 + public OvsdbNodeId nodeId() {
117 - @Override 117 + return nodeId;
118 - public void setAgent(OvsdbAgent agent) { 118 + }
119 - if (this.agent == null) { 119 +
120 - this.agent = agent; 120 + @Override
121 - } 121 + public void setAgent(OvsdbAgent agent) {
122 - } 122 + if (this.agent == null) {
123 - 123 + this.agent = agent;
124 - @Override 124 + }
125 - public void setChannel(Channel channel) { 125 + }
126 - this.channel = channel; 126 +
127 - } 127 + @Override
128 - 128 + public void setChannel(Channel channel) {
129 - @Override 129 + this.channel = channel;
130 - public void setConnection(boolean connected) { 130 + }
131 - this.connected = connected; 131 +
132 - } 132 + @Override
133 - 133 + public void setConnection(boolean connected) {
134 - @Override 134 + this.connected = connected;
135 - public boolean isConnected() { 135 + }
136 - return this.connected; 136 +
137 - } 137 + @Override
138 - 138 + public boolean isConnected() {
139 - @Override 139 + return this.connected;
140 - public void nodeAdded() { 140 + }
141 - this.agent.addConnectedNode(nodeId, this); 141 +
142 - } 142 + @Override
143 - 143 + public void nodeAdded() {
144 - @Override 144 + this.agent.addConnectedNode(nodeId, this);
145 - public void nodeRemoved() { 145 + }
146 - this.agent.removeConnectedNode(nodeId); 146 +
147 - channel.disconnect(); 147 + @Override
148 - } 148 + public void nodeRemoved() {
149 - 149 + this.agent.removeConnectedNode(nodeId);
150 - /** 150 + channel.disconnect();
151 - * Gets the ovsdb table store. 151 + }
152 - * 152 +
153 - * @param dbName the ovsdb database name 153 + /**
154 - * @return ovsTableStore, empty if table store is find 154 + * Gets the ovsdb table store.
155 - */ 155 + *
156 - private OvsdbTableStore getTableStore(String dbName) { 156 + * @param dbName the ovsdb database name
157 - if (ovsdbStore == null) { 157 + * @return ovsTableStore, empty if table store is find
158 - return null; 158 + */
159 - } 159 + private OvsdbTableStore getTableStore(String dbName) {
160 - return ovsdbStore.getOvsdbTableStore(dbName); 160 + if (ovsdbStore == null) {
161 - } 161 + return null;
162 - 162 + }
163 - /** 163 + return ovsdbStore.getOvsdbTableStore(dbName);
164 - * Gets the ovsdb row store. 164 + }
165 - * 165 +
166 - * @param dbName the ovsdb database name 166 + /**
167 - * @param tableName the ovsdb table name 167 + * Gets the ovsdb row store.
168 - * 168 + *
169 - * @return ovsRowStore, empty if row store is find 169 + * @param dbName the ovsdb database name
170 - */ 170 + * @param tableName the ovsdb table name
171 - private OvsdbRowStore getRowStore(String dbName, String tableName) { 171 + *
172 - OvsdbTableStore tableStore = getTableStore(dbName); 172 + * @return ovsRowStore, empty if row store is find
173 - if (tableStore == null) { 173 + */
174 - return null; 174 + private OvsdbRowStore getRowStore(String dbName, String tableName) {
175 - } 175 + OvsdbTableStore tableStore = getTableStore(dbName);
176 - return tableStore.getRows(tableName); 176 + if (tableStore == null) {
177 - } 177 + return null;
178 - 178 + }
179 - /** 179 + return tableStore.getRows(tableName);
180 - * Gets the ovsdb row. 180 + }
181 - * 181 +
182 - * @param dbName the ovsdb database name 182 + /**
183 - * @param tableName the ovsdb table name 183 + * Gets the ovsdb row.
184 - * @param uuid the key of the row 184 + *
185 - * @return row, empty if row is find 185 + * @param dbName the ovsdb database name
186 - */ 186 + * @param tableName the ovsdb table name
187 - @Override 187 + * @param uuid the key of the row
188 - public Row getRow(String dbName, String tableName, String uuid) { 188 + * @return row, empty if row is find
189 - OvsdbTableStore tableStore = getTableStore(dbName); 189 + */
190 - if (tableStore == null) { 190 + @Override
191 - return null; 191 + public Row getRow(String dbName, String tableName, String uuid) {
192 - } 192 + OvsdbTableStore tableStore = getTableStore(dbName);
193 - OvsdbRowStore rowStore = tableStore.getRows(tableName); 193 + if (tableStore == null) {
194 - if (rowStore == null) { 194 + return null;
195 - return null; 195 + }
196 - } 196 + OvsdbRowStore rowStore = tableStore.getRows(tableName);
197 - return rowStore.getRow(uuid); 197 + if (rowStore == null) {
198 - } 198 + return null;
199 - 199 + }
200 - @Override 200 + return rowStore.getRow(uuid);
201 - public void removeRow(String dbName, String tableName, String uuid) { 201 + }
202 - OvsdbTableStore tableStore = getTableStore(dbName); 202 +
203 - if (tableStore == null) { 203 + @Override
204 - return; 204 + public void removeRow(String dbName, String tableName, String uuid) {
205 - } 205 + OvsdbTableStore tableStore = getTableStore(dbName);
206 - OvsdbRowStore rowStore = tableStore.getRows(tableName); 206 + if (tableStore == null) {
207 - if (rowStore == null) { 207 + return;
208 - return; 208 + }
209 - } 209 + OvsdbRowStore rowStore = tableStore.getRows(tableName);
210 - rowStore.deleteRow(uuid); 210 + if (rowStore == null) {
211 - } 211 + return;
212 - 212 + }
213 - @Override 213 + rowStore.deleteRow(uuid);
214 - public void updateOvsdbStore(String dbName, String tableName, String uuid, 214 + }
215 - Row row) { 215 +
216 - OvsdbTableStore tableStore = ovsdbStore.getOvsdbTableStore(dbName); 216 + @Override
217 - if (tableStore == null) { 217 + public void updateOvsdbStore(String dbName, String tableName, String uuid,
218 - tableStore = new OvsdbTableStore(); 218 + Row row) {
219 - } 219 + OvsdbTableStore tableStore = ovsdbStore.getOvsdbTableStore(dbName);
220 - OvsdbRowStore rowStore = tableStore.getRows(tableName); 220 + if (tableStore == null) {
221 - if (rowStore == null) { 221 + tableStore = new OvsdbTableStore();
222 - rowStore = new OvsdbRowStore(); 222 + }
223 - } 223 + OvsdbRowStore rowStore = tableStore.getRows(tableName);
224 - rowStore.insertRow(uuid, row); 224 + if (rowStore == null) {
225 - tableStore.createOrUpdateTable(tableName, rowStore); 225 + rowStore = new OvsdbRowStore();
226 - ovsdbStore.createOrUpdateOvsdbStore(dbName, tableStore); 226 + }
227 - } 227 + rowStore.insertRow(uuid, row);
228 - 228 + tableStore.createOrUpdateTable(tableName, rowStore);
229 - @Override 229 + ovsdbStore.createOrUpdateOvsdbStore(dbName, tableStore);
230 - public String getPortUuid(String portName, String bridgeUuid) { 230 + }
231 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 231 +
232 - 232 + @Override
233 - Row bridgeRow = getRow(OvsdbConstant.DATABASENAME, 233 + public String getPortUuid(String portName, String bridgeUuid) {
234 - OvsdbConstant.BRIDGE, bridgeUuid); 234 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
235 - 235 +
236 - Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, 236 + Row bridgeRow = getRow(OvsdbConstant.DATABASENAME,
237 - OvsdbTable.BRIDGE); 237 + OvsdbConstant.BRIDGE, bridgeUuid);
238 - if (bridge != null) { 238 +
239 - OvsdbSet setPorts = (OvsdbSet) bridge.getPortsColumn().data(); 239 + Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow,
240 - @SuppressWarnings("unchecked") 240 + OvsdbTable.BRIDGE);
241 - Set<UUID> ports = setPorts.set(); 241 + if (bridge != null) {
242 - if (ports == null || ports.size() == 0) { 242 + OvsdbSet setPorts = (OvsdbSet) bridge.getPortsColumn().data();
243 - log.warn("The port uuid is null"); 243 + @SuppressWarnings("unchecked")
244 - return null; 244 + Set<UUID> ports = setPorts.set();
245 - } 245 + if (ports == null || ports.size() == 0) {
246 - 246 + log.warn("The port uuid is null");
247 - for (UUID uuid : ports) { 247 + return null;
248 - Row portRow = getRow(OvsdbConstant.DATABASENAME, 248 + }
249 - OvsdbConstant.PORT, uuid.value()); 249 +
250 - if (portRow == null) { 250 + for (UUID uuid : ports) {
251 - continue; 251 + Row portRow = getRow(OvsdbConstant.DATABASENAME,
252 - } 252 + OvsdbConstant.PORT, uuid.value());
253 - Port port = (Port) TableGenerator.getTable(dbSchema, portRow, 253 + Port port = (Port) TableGenerator.getTable(dbSchema, portRow,
254 - OvsdbTable.PORT); 254 + OvsdbTable.PORT);
255 - if (port != null && portName.equalsIgnoreCase(port.getName())) { 255 + if (port != null && portName.equalsIgnoreCase(port.getName())) {
256 - return uuid.value(); 256 + return uuid.value();
257 - } 257 + }
258 - } 258 + }
259 - 259 +
260 - } 260 + }
261 - return null; 261 + return null;
262 - } 262 + }
263 - 263 +
264 - @Override 264 + @Override
265 - public String getInterfaceUuid(String portUuid, String portName) { 265 + public String getInterfaceUuid(String portUuid, String portName) {
266 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 266 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
267 - 267 +
268 - Row portRow = getRow(OvsdbConstant.DATABASENAME, OvsdbConstant.PORT, 268 + Row portRow = getRow(OvsdbConstant.DATABASENAME, OvsdbConstant.PORT,
269 - portUuid); 269 + portUuid);
270 - Port port = (Port) TableGenerator.getTable(dbSchema, portRow, 270 + Port port = (Port) TableGenerator.getTable(dbSchema, portRow,
271 - OvsdbTable.PORT); 271 + OvsdbTable.PORT);
272 - 272 +
273 - if (port != null) { 273 + if (port != null) {
274 - OvsdbSet setInterfaces = (OvsdbSet) port.getInterfacesColumn().data(); 274 + OvsdbSet setInterfaces = (OvsdbSet) port.getInterfacesColumn().data();
275 - @SuppressWarnings("unchecked") 275 + @SuppressWarnings("unchecked")
276 - Set<UUID> interfaces = setInterfaces.set(); 276 + Set<UUID> interfaces = setInterfaces.set();
277 - 277 +
278 - if (interfaces == null || interfaces.size() == 0) { 278 + if (interfaces == null || interfaces.size() == 0) {
279 - log.warn("The interface uuid is null"); 279 + log.warn("The interface uuid is null");
280 - return null; 280 + return null;
281 - } 281 + }
282 - 282 +
283 - for (UUID uuid : interfaces) { 283 + for (UUID uuid : interfaces) {
284 - Row intfRow = getRow(OvsdbConstant.DATABASENAME, 284 + Row intfRow = getRow(OvsdbConstant.DATABASENAME,
285 - OvsdbConstant.INTERFACE, uuid.value()); 285 + OvsdbConstant.INTERFACE, uuid.value());
286 - if (intfRow == null) { 286 + Interface intf = (Interface) TableGenerator
287 - continue; 287 + .getTable(dbSchema, intfRow, OvsdbTable.INTERFACE);
288 - } 288 + if (intf != null && portName.equalsIgnoreCase(intf.getName())) {
289 - Interface intf = (Interface) TableGenerator 289 + return uuid.value();
290 - .getTable(dbSchema, intfRow, OvsdbTable.INTERFACE); 290 + }
291 - if (intf != null && portName.equalsIgnoreCase(intf.getName())) { 291 + }
292 - return uuid.value(); 292 +
293 - } 293 + }
294 - } 294 +
295 - 295 + return null;
296 - } 296 + }
297 - 297 +
298 - return null; 298 + @Override
299 - } 299 + public String getBridgeUuid(String bridgeName) {
300 - 300 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
301 - @Override 301 +
302 - public String getBridgeUuid(String bridgeName) { 302 + OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME,
303 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 303 + OvsdbConstant.BRIDGE);
304 - 304 + if (rowStore == null) {
305 - OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME, 305 + log.debug("The bridge uuid is null");
306 - OvsdbConstant.BRIDGE); 306 + return null;
307 - if (rowStore == null) { 307 + }
308 - log.debug("The bridge uuid is null"); 308 +
309 - return null; 309 + ConcurrentMap<String, Row> bridgeTableRows = rowStore.getRowStore();
310 - } 310 + if (bridgeTableRows == null) {
311 - 311 + log.debug("The bridge uuid is null");
312 - ConcurrentMap<String, Row> bridgeTableRows = rowStore.getRowStore(); 312 + return null;
313 - if (bridgeTableRows == null) { 313 + }
314 - log.debug("The bridge uuid is null"); 314 +
315 - return null; 315 + for (String uuid : bridgeTableRows.keySet()) {
316 - } 316 + Bridge bridge = (Bridge) TableGenerator
317 - 317 + .getTable(dbSchema, bridgeTableRows.get(uuid),
318 - for (String uuid : bridgeTableRows.keySet()) { 318 + OvsdbTable.BRIDGE);
319 - Bridge bridge = (Bridge) TableGenerator 319 +
320 - .getTable(dbSchema, bridgeTableRows.get(uuid), 320 + if (bridge.getName().equals(bridgeName)) {
321 - OvsdbTable.BRIDGE); 321 + return uuid;
322 - 322 + }
323 - if (bridge.getName().equals(bridgeName)) { 323 +
324 - return uuid; 324 + }
325 - } 325 + return null;
326 - 326 + }
327 - } 327 +
328 - return null; 328 + @Override
329 - } 329 + public String getControllerUuid(String controllerName,
330 - 330 + String controllerTarget) {
331 - @Override 331 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
332 - public String getControllerUuid(String controllerName, 332 + OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME,
333 - String controllerTarget) { 333 + OvsdbConstant.CONTROLLER);
334 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 334 + if (rowStore == null) {
335 - OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME, 335 + log.debug("The controller uuid is null");
336 - OvsdbConstant.CONTROLLER); 336 + return null;
337 - if (rowStore == null) { 337 + }
338 - log.debug("The controller uuid is null"); 338 +
339 - return null; 339 + ConcurrentMap<String, Row> controllerTableRows = rowStore.getRowStore();
340 - } 340 + if (controllerTableRows != null) {
341 - 341 + for (String uuid : controllerTableRows.keySet()) {
342 - ConcurrentMap<String, Row> controllerTableRows = rowStore.getRowStore(); 342 +
343 - if (controllerTableRows != null) { 343 + Controller controller = (Controller) TableGenerator
344 - for (String uuid : controllerTableRows.keySet()) { 344 + .getTable(dbSchema, controllerTableRows.get(uuid),
345 - 345 + OvsdbTable.CONTROLLER);
346 - Controller controller = (Controller) TableGenerator 346 + String target = (String) controller.getTargetColumn().data();
347 - .getTable(dbSchema, controllerTableRows.get(uuid), 347 + if (target.equalsIgnoreCase(controllerTarget)) {
348 - OvsdbTable.CONTROLLER); 348 + return uuid;
349 - String target = (String) controller.getTargetColumn().data(); 349 + }
350 - if (target.equalsIgnoreCase(controllerTarget)) { 350 +
351 - return uuid; 351 + }
352 - } 352 + }
353 - 353 + return null;
354 - } 354 + }
355 - } 355 +
356 - return null; 356 + @Override
357 - } 357 + public String getOvsUuid(String dbName) {
358 - 358 + OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME,
359 - @Override 359 + OvsdbConstant.DATABASENAME);
360 - public String getOvsUuid(String dbName) { 360 + if (rowStore == null) {
361 - OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME, 361 + log.debug("The bridge uuid is null");
362 - OvsdbConstant.DATABASENAME); 362 + return null;
363 - if (rowStore == null) { 363 + }
364 - log.debug("The bridge uuid is null"); 364 + ConcurrentMap<String, Row> ovsTableRows = rowStore.getRowStore();
365 - return null; 365 + if (ovsTableRows != null) {
366 - } 366 + for (String uuid : ovsTableRows.keySet()) {
367 - ConcurrentMap<String, Row> ovsTableRows = rowStore.getRowStore(); 367 + Row row = ovsTableRows.get(uuid);
368 - if (ovsTableRows != null) { 368 + String tableName = row.tableName();
369 - for (String uuid : ovsTableRows.keySet()) { 369 + if (tableName.equals(dbName)) {
370 - Row row = ovsTableRows.get(uuid); 370 + return uuid;
371 - String tableName = row.tableName(); 371 + }
372 - if (tableName.equals(dbName)) { 372 + }
373 - return uuid; 373 + }
374 - } 374 + return null;
375 - } 375 + }
376 - } 376 +
377 - return null; 377 + @Override
378 - } 378 + public void createPort(String bridgeName, String portName) {
379 - 379 + String bridgeUuid = getBridgeUuid(bridgeName);
380 - @Override 380 + if (bridgeUuid == null) {
381 - public void createPort(String bridgeName, String portName) { 381 + log.error("Can't find bridge {} in {}", bridgeName,
382 - String bridgeUuid = getBridgeUuid(bridgeName); 382 + nodeId.getIpAddress());
383 - if (bridgeUuid == null) { 383 + return;
384 - log.error("Can't find bridge {} in {}", bridgeName, 384 + }
385 - nodeId.getIpAddress()); 385 +
386 - return; 386 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
387 - } 387 + String portUuid = getPortUuid(portName, bridgeUuid);
388 - 388 +
389 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 389 + Port port = (Port) TableGenerator
390 - String portUuid = getPortUuid(portName, bridgeUuid); 390 + .createTable(dbSchema, OvsdbTable.PORT);
391 - 391 +
392 - Port port = (Port) TableGenerator 392 + port.setName(portName);
393 - .createTable(dbSchema, OvsdbTable.PORT); 393 + if (portUuid == null) {
394 - 394 + insertConfig(OvsdbConstant.PORT, "_uuid", OvsdbConstant.BRIDGE,
395 - port.setName(portName); 395 + "ports", bridgeUuid, port.getRow());
396 - if (portUuid == null) { 396 + } else {
397 - insertConfig(OvsdbConstant.PORT, "_uuid", OvsdbConstant.BRIDGE, 397 + updateConfig(OvsdbConstant.PORT, "_uuid", portUuid, port.getRow());
398 - "ports", bridgeUuid, port.getRow()); 398 + }
399 - } else { 399 +
400 - updateConfig(OvsdbConstant.PORT, "_uuid", portUuid, port.getRow()); 400 + return;
401 - } 401 + }
402 - 402 +
403 - return; 403 + @Override
404 - } 404 + public void dropPort(String bridgeName, String portName) {
405 - 405 + String bridgeUuid = getBridgeUuid(bridgeName);
406 - @Override 406 + if (bridgeUuid == null) {
407 - public void dropPort(String bridgeName, String portName) { 407 + log.error("Could not find Bridge {} in {}", bridgeName, nodeId);
408 - String bridgeUuid = getBridgeUuid(bridgeName); 408 + return;
409 - if (bridgeUuid == null) { 409 + }
410 - log.error("Could not find Bridge {} in {}", bridgeName, nodeId); 410 +
411 - return; 411 + String portUuid = getPortUuid(portName, bridgeUuid);
412 - } 412 + if (portUuid != null) {
413 - 413 + log.info("Port {} delete", portName);
414 - String portUuid = getPortUuid(portName, bridgeUuid); 414 + deleteConfig(OvsdbConstant.PORT, "_uuid", portUuid,
415 - if (portUuid != null) { 415 + OvsdbConstant.BRIDGE, "ports");
416 - log.info("Port {} delete", portName); 416 + }
417 - deleteConfig(OvsdbConstant.PORT, "_uuid", portUuid, 417 + }
418 - OvsdbConstant.BRIDGE, "ports"); 418 +
419 - } 419 + @Override
420 - } 420 + public void createBridge(String bridgeName) {
421 - 421 + log.debug("create bridge {}", bridgeName);
422 - @Override 422 +
423 - public void createBridge(String bridgeName) { 423 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
424 - log.debug("create bridge {}", bridgeName); 424 + if (dbSchema == null) {
425 - 425 + log.warn("The schema is null");
426 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 426 + return;
427 - if (dbSchema == null) { 427 + }
428 - log.warn("The schema is null"); 428 +
429 - return; 429 + Bridge bridge = (Bridge) TableGenerator.createTable(dbSchema,
430 - } 430 + OvsdbTable.BRIDGE);
431 - 431 + if (bridge == null) {
432 - Bridge bridge = (Bridge) TableGenerator.createTable(dbSchema, 432 + log.debug("Can not create bridge");
433 - OvsdbTable.BRIDGE); 433 + return;
434 - if (bridge == null) { 434 + }
435 - log.debug("Can not create bridge"); 435 +
436 - return; 436 + Set<String> failModes = new HashSet<>();
437 - } 437 + failModes.add("secure");
438 - 438 + bridge.setFailMode(failModes);
439 - Set<String> failModes = new HashSet<>(); 439 +
440 - failModes.add("secure"); 440 + Set<String> protocols = new HashSet<>();
441 - bridge.setFailMode(failModes); 441 + protocols.add(OvsdbConstant.OPENFLOW13);
442 - 442 + bridge.setProtocols(protocols);
443 - Set<String> protocols = new HashSet<>(); 443 +
444 - protocols.add(OvsdbConstant.OPENFLOW13); 444 + String ovsUuid = getOvsUuid(OvsdbConstant.DATABASENAME);
445 - bridge.setProtocols(protocols); 445 + if (ovsUuid == null) {
446 - 446 + log.warn("The Open_vSwitch is null");
447 - String ovsUuid = getOvsUuid(OvsdbConstant.DATABASENAME); 447 + return;
448 - if (ovsUuid == null) { 448 + }
449 - log.warn("The Open_vSwitch is null"); 449 +
450 - return; 450 + String bridgeUuid = getBridgeUuid(bridgeName);
451 - } 451 + if (bridgeUuid == null) {
452 - 452 + log.debug("Create a new bridge");
453 - String bridgeUuid = getBridgeUuid(bridgeName); 453 +
454 - if (bridgeUuid == null) { 454 + bridge.setName(bridgeName);
455 - log.debug("Create a new bridge"); 455 + bridgeUuid = insertConfig(OvsdbConstant.BRIDGE, "_uuid",
456 - 456 + OvsdbConstant.DATABASENAME, "bridges",
457 - bridge.setName(bridgeName); 457 + ovsUuid, bridge.getRow());
458 - bridgeUuid = insertConfig(OvsdbConstant.BRIDGE, "_uuid", 458 +
459 - OvsdbConstant.DATABASENAME, "bridges", 459 + if (bridgeUuid != null) {
460 - ovsUuid, bridge.getRow()); 460 + Port port = (Port) TableGenerator.createTable(dbSchema,
461 - 461 + OvsdbTable.PORT);
462 - if (bridgeUuid != null) { 462 + if (port != null) {
463 - Port port = (Port) TableGenerator.createTable(dbSchema, 463 + log.debug("the port is not null");
464 - OvsdbTable.PORT); 464 + port.setName(bridgeName);
465 - if (port != null) { 465 +
466 - log.debug("the port is not null"); 466 + insertConfig(OvsdbConstant.PORT, "_uuid", "Bridge", "ports", bridgeUuid,
467 - port.setName(bridgeName); 467 + port.getRow());
468 - 468 + }
469 - insertConfig(OvsdbConstant.PORT, "_uuid", "Bridge", "ports", bridgeUuid, 469 + }
470 - port.getRow()); 470 +
471 - } 471 + } else {
472 - } 472 + log.info("Update a bridge");
473 - 473 + updateConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUuid, bridge.getRow());
474 - } else { 474 + }
475 - log.info("Update a bridge"); 475 +
476 - updateConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUuid, bridge.getRow()); 476 + setController(bridgeUuid);
477 - } 477 + log.info("Create bridge success");
478 - 478 + }
479 - setController(bridgeUuid); 479 +
480 - log.info("Create bridge success"); 480 + /**
481 - } 481 + * Sets the Controller.
482 - 482 + *
483 - /** 483 + * @param bridgeUuid bridge uuid
484 - * Sets the Controller. 484 + */
485 - * 485 + private void setController(String bridgeUuid) {
486 - * @param bridgeUuid bridge uuid 486 + String controllerUuid = null;
487 - */ 487 + String iPAddress = IpAddress.valueOf(((InetSocketAddress) channel
488 - private void setController(String bridgeUuid) { 488 + .localAddress())
489 - String controllerUuid = null; 489 + .getAddress()
490 - String iPAddress = IpAddress.valueOf(((InetSocketAddress) channel 490 + .getHostAddress())
491 - .localAddress()) 491 + .toString();
492 - .getAddress() 492 +
493 - .getHostAddress()) 493 + String target = "tcp:" + iPAddress + ":" + OvsdbConstant.OFPORT;
494 - .toString(); 494 + log.debug("controller IP {}: port {}", iPAddress, OvsdbConstant.OFPORT);
495 - 495 +
496 - String target = "tcp:" + iPAddress + ":" + OvsdbConstant.OFPORT; 496 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
497 - log.debug("controller IP {}: port {}", iPAddress, OvsdbConstant.OFPORT); 497 + Controller controller = (Controller) TableGenerator
498 - 498 + .createTable(dbSchema, OvsdbTable.CONTROLLER);
499 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 499 +
500 - Controller controller = (Controller) TableGenerator 500 + if (controller != null) {
501 - .createTable(dbSchema, OvsdbTable.CONTROLLER); 501 + controller.setTarget(target);
502 - 502 + controllerUuid = getControllerUuid(OvsdbConstant.CONTROLLER, target);
503 - if (controller != null) { 503 + if (controllerUuid == null) {
504 - controller.setTarget(target); 504 +
505 - controllerUuid = getControllerUuid(OvsdbConstant.CONTROLLER, target); 505 + insertConfig(OvsdbConstant.CONTROLLER, "_uuid",
506 - if (controllerUuid == null) { 506 + OvsdbConstant.BRIDGE, "controller", bridgeUuid,
507 - 507 + controller.getRow());
508 - insertConfig(OvsdbConstant.CONTROLLER, "_uuid", 508 +
509 - OvsdbConstant.BRIDGE, "controller", bridgeUuid, 509 + } else {
510 - controller.getRow()); 510 +
511 - 511 + Bridge bridge = (Bridge) TableGenerator
512 - } else { 512 + .createTable(dbSchema, OvsdbTable.BRIDGE);
513 - 513 + Set<UUID> controllerUuids = new HashSet<>();
514 - Bridge bridge = (Bridge) TableGenerator 514 + controllerUuids.add(UUID.uuid(controllerUuid));
515 - .createTable(dbSchema, OvsdbTable.BRIDGE); 515 + bridge.setController(controllerUuids);
516 - Set<UUID> controllerUuids = new HashSet<>(); 516 + updateConfig(OvsdbConstant.CONTROLLER, "_uuid", bridgeUuid, bridge.getRow());
517 - controllerUuids.add(UUID.uuid(controllerUuid)); 517 +
518 - bridge.setController(controllerUuids); 518 + }
519 - updateConfig(OvsdbConstant.CONTROLLER, "_uuid", bridgeUuid, bridge.getRow()); 519 + }
520 - 520 +
521 - } 521 + }
522 - } 522 +
523 - 523 + @Override
524 - } 524 + public void dropBridge(String bridgeName) {
525 - 525 + String bridgeUUID = getBridgeUuid(bridgeName);
526 - @Override 526 + if (bridgeUUID == null) {
527 - public void dropBridge(String bridgeName) { 527 + log.warn("Could not find bridge in node", nodeId.getIpAddress());
528 - String bridgeUUID = getBridgeUuid(bridgeName); 528 + return;
529 - if (bridgeUUID == null) { 529 + }
530 - log.warn("Could not find bridge in node", nodeId.getIpAddress()); 530 + deleteConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUUID,
531 - return; 531 + OvsdbConstant.DATABASENAME, "bridges");
532 - } 532 + }
533 - deleteConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUUID, 533 +
534 - OvsdbConstant.DATABASENAME, "bridges"); 534 + @Override
535 - } 535 + public void createTunnel(IpAddress srcIp, IpAddress dstIp) {
536 - 536 + String bridgeUuid = getBridgeUuid(OvsdbConstant.INTEGRATION_BRIDGE);
537 - @Override 537 + if (bridgeUuid == null) {
538 - public void createTunnel(IpAddress srcIp, IpAddress dstIp) { 538 + log.warn("Could not find bridge {} and Could not create tunnel. ",
539 - String bridgeUuid = getBridgeUuid(OvsdbConstant.INTEGRATION_BRIDGE); 539 + OvsdbConstant.INTEGRATION_BRIDGE);
540 - if (bridgeUuid == null) { 540 + return;
541 - log.warn("Could not find bridge {} and Could not create tunnel. ", 541 + }
542 - OvsdbConstant.INTEGRATION_BRIDGE); 542 +
543 - return; 543 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
544 - } 544 + String portName = getTunnelName(OvsdbConstant.TYPEVXLAN, dstIp);
545 - 545 + String portUuid = getPortUuid(portName, bridgeUuid);
546 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 546 +
547 - String portName = getTunnelName(OvsdbConstant.TYPEVXLAN, dstIp); 547 + Port port = (Port) TableGenerator
548 - String portUuid = getPortUuid(portName, bridgeUuid); 548 + .createTable(dbSchema, OvsdbTable.PORT);
549 - 549 + if (port != null) {
550 - Port port = (Port) TableGenerator 550 + port.setName(portName);
551 - .createTable(dbSchema, OvsdbTable.PORT); 551 + }
552 - if (port != null) { 552 +
553 - port.setName(portName); 553 + if (portUuid == null) {
554 - } 554 + portUuid = insertConfig(OvsdbConstant.PORT, "_uuid", OvsdbConstant.BRIDGE,
555 - 555 + "ports", bridgeUuid, port.getRow());
556 - if (portUuid == null) { 556 + } else {
557 - portUuid = insertConfig(OvsdbConstant.PORT, "_uuid", OvsdbConstant.BRIDGE, 557 + updateConfig(OvsdbConstant.PORT, "_uuid", portUuid, port.getRow());
558 - "ports", bridgeUuid, port.getRow()); 558 + }
559 - } else { 559 +
560 - updateConfig(OvsdbConstant.PORT, "_uuid", portUuid, port.getRow()); 560 + // When a tunnel is created, A row is inserted into port table and
561 - } 561 + // interface table of the ovsdb node.
562 - 562 + // and the following step is to get the interface uuid from local store
563 - // When a tunnel is created, A row is inserted into port table and 563 + // in controller node.
564 - // interface table of the ovsdb node. 564 + // but it need spend some time synchronising data between node and
565 - // and the following step is to get the interface uuid from local store 565 + // controller.
566 - // in controller node. 566 + // so loop to judge if interfaceUUid is null is necessary.
567 - // but it need spend some time synchronising data between node and 567 + String interfaceUuid = null;
568 - // controller. 568 + for (int i = 0; i < 10; i++) {
569 - // so loop to judge if interfaceUUid is null is necessary. 569 + interfaceUuid = getInterfaceUuid(portUuid, portName);
570 - String interfaceUuid = null; 570 + if (interfaceUuid == null) {
571 - for (int i = 0; i < 10; i++) { 571 + try {
572 - interfaceUuid = getInterfaceUuid(portUuid, portName); 572 + Thread.sleep(500);
573 - if (interfaceUuid == null) { 573 + } catch (InterruptedException e) {
574 - try { 574 + log.warn("Interrupted while waiting to get interfaceUuid");
575 - Thread.sleep(500); 575 + Thread.currentThread().interrupt();
576 - } catch (InterruptedException e) { 576 + }
577 - log.warn("Interrupted while waiting to get interfaceUuid"); 577 + } else {
578 - Thread.currentThread().interrupt(); 578 + break;
579 - } 579 + }
580 - } else { 580 + }
581 - break; 581 +
582 - } 582 + if (interfaceUuid != null) {
583 - } 583 +
584 - 584 + Interface tunInterface = (Interface) TableGenerator
585 - if (interfaceUuid != null) { 585 + .createTable(dbSchema, OvsdbTable.INTERFACE);
586 - OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME, 586 +
587 - OvsdbConstant.INTERFACE); 587 + if (tunInterface != null) {
588 - if (rowStore == null) { 588 +
589 - log.debug("The bridge uuid is null"); 589 + tunInterface.setType(OvsdbConstant.TYPEVXLAN);
590 - return; 590 + Map<String, String> options = Maps.newHashMap();
591 - } 591 + options.put("key", "flow");
592 - 592 + options.put("local_ip", srcIp.toString());
593 - ConcurrentMap<String, Row> intfTableRows = rowStore.getRowStore(); 593 + options.put("remote_ip", dstIp.toString());
594 - if (intfTableRows == null) { 594 + tunInterface.setOptions(options);
595 - log.debug("The bridge uuid is null"); 595 + updateConfig(OvsdbConstant.INTERFACE, "_uuid", interfaceUuid,
596 - return; 596 + tunInterface.getRow());
597 - } 597 + log.info("Tunnel added success", tunInterface);
598 - 598 +
599 - Interface tunInterface = (Interface) TableGenerator 599 + }
600 - .getTable(dbSchema, intfTableRows.get(interfaceUuid), 600 + }
601 - OvsdbTable.INTERFACE); 601 +
602 - if (tunInterface != null) { 602 + return;
603 - 603 + }
604 - tunInterface.setType(OvsdbConstant.TYPEVXLAN); 604 +
605 - Map<String, String> options = Maps.newHashMap(); 605 + @Override
606 - options.put("key", "flow"); 606 + public void dropTunnel(IpAddress srcIp, IpAddress dstIp) {
607 - options.put("local_ip", srcIp.toString()); 607 + String bridgeName = OvsdbConstant.INTEGRATION_BRIDGE;
608 - options.put("remote_ip", dstIp.toString()); 608 + String portName = getTunnelName(OvsdbConstant.TYPEVXLAN, dstIp);
609 - tunInterface.setOptions(options); 609 + String bridgeUuid = getBridgeUuid(OvsdbConstant.INTEGRATION_BRIDGE);
610 - updateConfig(OvsdbConstant.INTERFACE, "_uuid", interfaceUuid, 610 + if (bridgeUuid == null) {
611 - tunInterface.getRow()); 611 + log.warn("Could not find bridge {} in {}", bridgeName,
612 - log.info("Tunnel added success", tunInterface); 612 + nodeId.getIpAddress());
613 - 613 + return;
614 - } 614 + }
615 - } 615 +
616 - 616 + String portUUID = getPortUuid(portName, bridgeUuid);
617 - return; 617 + if (portUUID != null) {
618 - } 618 + log.info("Delete tunnel");
619 - 619 + deleteConfig(OvsdbConstant.PORT, "_uuid", portUUID,
620 - @Override 620 + OvsdbConstant.BRIDGE, "ports");
621 - public void dropTunnel(IpAddress srcIp, IpAddress dstIp) { 621 + }
622 - String bridgeName = OvsdbConstant.INTEGRATION_BRIDGE; 622 +
623 - String portName = getTunnelName(OvsdbConstant.TYPEVXLAN, dstIp); 623 + return;
624 - String bridgeUuid = getBridgeUuid(OvsdbConstant.INTEGRATION_BRIDGE); 624 + }
625 - if (bridgeUuid == null) { 625 +
626 - log.warn("Could not find bridge {} in {}", bridgeName, 626 + /**
627 - nodeId.getIpAddress()); 627 + * Delete transact config.
628 - return; 628 + *
629 - } 629 + * @param childTableName child table name
630 - 630 + * @param childColumnName child column name
631 - String portUUID = getPortUuid(portName, bridgeUuid); 631 + * @param childUuid child row uuid
632 - if (portUUID != null) { 632 + * @param parentTableName parent table name
633 - log.info("Delete tunnel"); 633 + * @param parentColumnName parent column
634 - deleteConfig(OvsdbConstant.PORT, "_uuid", portUUID, 634 + *
635 - OvsdbConstant.BRIDGE, "ports"); 635 + */
636 - } 636 + private void deleteConfig(String childTableName, String childColumnName,
637 - 637 + String childUuid, String parentTableName,
638 - return; 638 + String parentColumnName) {
639 - } 639 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
640 - 640 + TableSchema childTableSchema = dbSchema.getTableSchema(childTableName);
641 - /** 641 +
642 - * Delete transact config. 642 + ArrayList<Operation> operations = Lists.newArrayList();
643 - * 643 + if (parentTableName != null && parentColumnName != null) {
644 - * @param childTableName child table name 644 + TableSchema parentTableSchema = dbSchema
645 - * @param childColumnName child column name 645 + .getTableSchema(parentTableName);
646 - * @param childUuid child row uuid 646 + ColumnSchema parentColumnSchema = parentTableSchema
647 - * @param parentTableName parent table name 647 + .getColumnSchema(parentColumnName);
648 - * @param parentColumnName parent column 648 + List<Mutation> mutations = Lists.newArrayList();
649 - * 649 + Mutation mutation = MutationUtil.delete(parentColumnSchema.name(),
650 - */ 650 + UUID.uuid(childUuid));
651 - private void deleteConfig(String childTableName, String childColumnName, 651 + mutations.add(mutation);
652 - String childUuid, String parentTableName, 652 + List<Condition> conditions = Lists.newArrayList();
653 - String parentColumnName) { 653 + Condition condition = ConditionUtil.includes(parentColumnName,
654 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 654 + UUID.uuid(childUuid));
655 - TableSchema childTableSchema = dbSchema.getTableSchema(childTableName); 655 + conditions.add(condition);
656 - 656 + Mutate op = new Mutate(parentTableSchema, conditions, mutations);
657 - ArrayList<Operation> operations = Lists.newArrayList(); 657 + operations.add(op);
658 - if (parentTableName != null && parentColumnName != null) { 658 + }
659 - TableSchema parentTableSchema = dbSchema 659 +
660 - .getTableSchema(parentTableName); 660 + List<Condition> conditions = Lists.newArrayList();
661 - ColumnSchema parentColumnSchema = parentTableSchema 661 + Condition condition = ConditionUtil.equals(childColumnName, UUID.uuid(childUuid));
662 - .getColumnSchema(parentColumnName); 662 + conditions.add(condition);
663 - List<Mutation> mutations = Lists.newArrayList(); 663 + Delete del = new Delete(childTableSchema, conditions);
664 - Mutation mutation = MutationUtil.delete(parentColumnSchema.name(), 664 + operations.add(del);
665 - UUID.uuid(childUuid)); 665 + transactConfig(OvsdbConstant.DATABASENAME, operations);
666 - mutations.add(mutation); 666 +
667 - List<Condition> conditions = Lists.newArrayList(); 667 + return;
668 - Condition condition = ConditionUtil.includes(parentColumnName, 668 + }
669 - UUID.uuid(childUuid)); 669 +
670 - conditions.add(condition); 670 + /**
671 - Mutate op = new Mutate(parentTableSchema, conditions, mutations); 671 + * Update transact config.
672 - operations.add(op); 672 + *
673 - } 673 + * @param tableName table name
674 - 674 + * @param columnName column name
675 - List<Condition> conditions = Lists.newArrayList(); 675 + * @param uuid uuid
676 - Condition condition = ConditionUtil.equals(childColumnName, UUID.uuid(childUuid)); 676 + * @param row the config data
677 - conditions.add(condition); 677 + *
678 - Delete del = new Delete(childTableSchema, conditions); 678 + */
679 - operations.add(del); 679 + private void updateConfig(String tableName, String columnName, String uuid,
680 - transactConfig(OvsdbConstant.DATABASENAME, operations); 680 + Row row) {
681 - 681 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
682 - return; 682 + TableSchema tableSchema = dbSchema.getTableSchema(tableName);
683 - } 683 +
684 - 684 + List<Condition> conditions = Lists.newArrayList();
685 - /** 685 + Condition condition = ConditionUtil.equals(columnName, UUID.uuid(uuid));
686 - * Update transact config. 686 + conditions.add(condition);
687 - * 687 +
688 - * @param tableName table name 688 + Update update = new Update(tableSchema, row, conditions);
689 - * @param columnName column name 689 +
690 - * @param uuid uuid 690 + ArrayList<Operation> operations = Lists.newArrayList();
691 - * @param row the config data 691 + operations.add(update);
692 - * 692 +
693 - */ 693 + transactConfig(OvsdbConstant.DATABASENAME, operations);
694 - private void updateConfig(String tableName, String columnName, String uuid, 694 + }
695 - Row row) { 695 +
696 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 696 + /**
697 - TableSchema tableSchema = dbSchema.getTableSchema(tableName); 697 + * Insert transact config.
698 - 698 + *
699 - List<Condition> conditions = Lists.newArrayList(); 699 + * @param childTableName child table name
700 - Condition condition = ConditionUtil.equals(columnName, UUID.uuid(uuid)); 700 + * @param childColumnName child column name
701 - conditions.add(condition); 701 + * @param parentTableName parent table name
702 - 702 + * @param parentColumnName parent column
703 - Update update = new Update(tableSchema, row, conditions); 703 + * @param parentUuid parent uuid
704 - 704 + * @param row the config data
705 - ArrayList<Operation> operations = Lists.newArrayList(); 705 + *
706 - operations.add(update); 706 + * @return uuid, empty if no uuid is find
707 - 707 + */
708 - transactConfig(OvsdbConstant.DATABASENAME, operations); 708 + private String insertConfig(String childTableName, String childColumnName,
709 - } 709 + String parentTableName, String parentColumnName,
710 - 710 + String parentUuid, Row row) {
711 - /** 711 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
712 - * Insert transact config. 712 + TableSchema tableSchema = dbSchema.getTableSchema(childTableName);
713 - * 713 +
714 - * @param childTableName child table name 714 + String namedUuid = childTableName;
715 - * @param childColumnName child column name 715 + Insert insert = new Insert(tableSchema, namedUuid, row);
716 - * @param parentTableName parent table name 716 +
717 - * @param parentColumnName parent column 717 + ArrayList<Operation> operations = Lists.newArrayList();
718 - * @param parentUuid parent uuid 718 + operations.add(insert);
719 - * @param row the config data 719 +
720 - * 720 + if (parentTableName != null && parentColumnName != null) {
721 - * @return uuid, empty if no uuid is find 721 + TableSchema parentTableSchema = dbSchema
722 - */ 722 + .getTableSchema(parentTableName);
723 - private String insertConfig(String childTableName, String childColumnName, 723 + ColumnSchema parentColumnSchema = parentTableSchema
724 - String parentTableName, String parentColumnName, 724 + .getColumnSchema(parentColumnName);
725 - String parentUuid, Row row) { 725 +
726 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 726 + List<Mutation> mutations = Lists.newArrayList();
727 - TableSchema tableSchema = dbSchema.getTableSchema(childTableName); 727 + Mutation mutation = MutationUtil.insert(parentColumnSchema.name(),
728 - 728 + UUID.uuid(namedUuid));
729 - String namedUuid = childTableName; 729 + mutations.add(mutation);
730 - Insert insert = new Insert(tableSchema, namedUuid, row); 730 +
731 - 731 + List<Condition> conditions = Lists.newArrayList();
732 - ArrayList<Operation> operations = Lists.newArrayList(); 732 + Condition condition = ConditionUtil.equals("_uuid",
733 - operations.add(insert); 733 + UUID.uuid(parentUuid));
734 - 734 + conditions.add(condition);
735 - if (parentTableName != null && parentColumnName != null) { 735 +
736 - TableSchema parentTableSchema = dbSchema 736 + Mutate op = new Mutate(parentTableSchema, conditions, mutations);
737 - .getTableSchema(parentTableName); 737 + operations.add(op);
738 - ColumnSchema parentColumnSchema = parentTableSchema 738 + }
739 - .getColumnSchema(parentColumnName); 739 + if (childTableName.equalsIgnoreCase(OvsdbConstant.PORT)) {
740 - 740 + log.info("Handle port insert");
741 - List<Mutation> mutations = Lists.newArrayList(); 741 + Insert intfInsert = handlePortInsertTable(OvsdbConstant.INTERFACE,
742 - Mutation mutation = MutationUtil.insert(parentColumnSchema.name(), 742 + row);
743 - UUID.uuid(namedUuid)); 743 +
744 - mutations.add(mutation); 744 + if (intfInsert != null) {
745 - 745 + operations.add(intfInsert);
746 - List<Condition> conditions = Lists.newArrayList(); 746 + }
747 - Condition condition = ConditionUtil.equals("_uuid", 747 +
748 - UUID.uuid(parentUuid)); 748 + Insert ins = (Insert) operations.get(0);
749 - conditions.add(condition); 749 + ins.getRow().put("interfaces",
750 - 750 + UUID.uuid(OvsdbConstant.INTERFACE));
751 - Mutate op = new Mutate(parentTableSchema, conditions, mutations); 751 + }
752 - operations.add(op); 752 +
753 - } 753 + List<OperationResult> results;
754 - if (childTableName.equalsIgnoreCase(OvsdbConstant.PORT)) { 754 + try {
755 - log.info("Handle port insert"); 755 + results = transactConfig(OvsdbConstant.DATABASENAME, operations)
756 - Insert intfInsert = handlePortInsertTable(OvsdbConstant.INTERFACE, 756 + .get();
757 - row); 757 +
758 - 758 + return results.get(0).getUuid().value();
759 - if (intfInsert != null) { 759 + } catch (InterruptedException e) {
760 - operations.add(intfInsert); 760 + log.warn("Interrupted while waiting to get result");
761 - } 761 + Thread.currentThread().interrupt();
762 - 762 + } catch (ExecutionException e) {
763 - Insert ins = (Insert) operations.get(0); 763 + log.error("Exception thrown while to get result");
764 - ins.getRow().put("interfaces", 764 + }
765 - UUID.uuid(OvsdbConstant.INTERFACE)); 765 +
766 - } 766 + return null;
767 - 767 + }
768 - List<OperationResult> results; 768 +
769 - try { 769 + /**
770 - results = transactConfig(OvsdbConstant.DATABASENAME, operations) 770 + * Handles port insert.
771 - .get(); 771 + *
772 - 772 + * @param tableName ovsdb table interface
773 - return results.get(0).getUuid().value(); 773 + * @param portRow row of port
774 - } catch (InterruptedException e) { 774 + *
775 - log.warn("Interrupted while waiting to get result"); 775 + * @return insert, empty if null
776 - Thread.currentThread().interrupt(); 776 + */
777 - } catch (ExecutionException e) { 777 + private Insert handlePortInsertTable(String tableName, Row portRow) {
778 - log.error("Exception thrown while to get result"); 778 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
779 - } 779 +
780 - 780 + TableSchema portTableSchema = dbSchema
781 - return null; 781 + .getTableSchema(OvsdbConstant.PORT);
782 - } 782 + ColumnSchema portColumnSchema = portTableSchema.getColumnSchema("name");
783 - 783 +
784 - /** 784 + String portName = (String) portRow.getColumn(portColumnSchema.name()).data();
785 - * Handles port insert. 785 +
786 - * 786 + Interface inf = (Interface) TableGenerator
787 - * @param tableName ovsdb table interface 787 + .createTable(dbSchema, OvsdbTable.INTERFACE);
788 - * @param portRow row of port 788 +
789 - * 789 + inf.setName(portName);
790 - * @return insert, empty if null 790 +
791 - */ 791 + TableSchema intfTableSchema = dbSchema
792 - private Insert handlePortInsertTable(String tableName, Row portRow) { 792 + .getTableSchema(OvsdbConstant.INTERFACE);
793 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 793 + Insert insert = new Insert(intfTableSchema, OvsdbConstant.INTERFACE,
794 - 794 + inf.getRow());
795 - TableSchema portTableSchema = dbSchema 795 + return insert;
796 - .getTableSchema(OvsdbConstant.PORT); 796 + }
797 - ColumnSchema portColumnSchema = portTableSchema.getColumnSchema("name"); 797 +
798 - 798 + /**
799 - String portName = (String) portRow.getColumn(portColumnSchema.name()).data(); 799 + * Gets tunnel name.
800 - 800 + *
801 - Interface inf = (Interface) TableGenerator 801 + * @param tunnelType
802 - .createTable(dbSchema, OvsdbTable.INTERFACE); 802 + * @param dstIp the remote ip address
803 - 803 + *
804 - inf.setName(portName); 804 + * @return tunnel name
805 - 805 + */
806 - TableSchema intfTableSchema = dbSchema 806 + private String getTunnelName(String tunnelType, IpAddress dstIp) {
807 - .getTableSchema(OvsdbConstant.INTERFACE); 807 + return tunnelType + "-" + dstIp.toString();
808 - Insert insert = new Insert(intfTableSchema, OvsdbConstant.INTERFACE, 808 + }
809 - inf.getRow()); 809 +
810 - return insert; 810 + @Override
811 - } 811 + public ListenableFuture<DatabaseSchema> getOvsdbSchema(String dbName) {
812 - 812 + if (dbName == null) {
813 - /** 813 + return null;
814 - * Gets tunnel name. 814 + }
815 - * 815 + DatabaseSchema databaseSchema = schema.get(dbName);
816 - * @param tunnelType 816 + if (databaseSchema == null) {
817 - * @param dstIp the remote ip address 817 + List<String> dbNames = new ArrayList<String>();
818 - * 818 + dbNames.add(dbName);
819 - * @return tunnel name 819 + Function<JsonNode, DatabaseSchema> rowFunction = new Function<JsonNode, DatabaseSchema>() {
820 - */ 820 + @Override
821 - private String getTunnelName(String tunnelType, IpAddress dstIp) { 821 + public DatabaseSchema apply(JsonNode input) {
822 - return tunnelType + "-" + dstIp.toString(); 822 + log.info("Get ovsdb database schema", dbName);
823 - } 823 + DatabaseSchema dbSchema = FromJsonUtil
824 - 824 + .jsonNodeToDbSchema(dbName, input);
825 - @Override 825 + if (dbSchema == null) {
826 - public ListenableFuture<DatabaseSchema> getOvsdbSchema(String dbName) { 826 + log.debug("Get ovsdb database schema error");
827 - if (dbName == null) { 827 + return null;
828 - return null; 828 + }
829 - } 829 + schema.put(dbName, dbSchema);
830 - DatabaseSchema databaseSchema = schema.get(dbName); 830 +
831 - if (databaseSchema == null) { 831 + return dbSchema;
832 - List<String> dbNames = new ArrayList<String>(); 832 + }
833 - dbNames.add(dbName); 833 + };
834 - Function<JsonNode, DatabaseSchema> rowFunction = new Function<JsonNode, DatabaseSchema>() { 834 +
835 - @Override 835 + ListenableFuture<JsonNode> input = getSchema(dbNames);
836 - public DatabaseSchema apply(JsonNode input) { 836 + if (input != null) {
837 - log.info("Get ovsdb database schema", dbName); 837 + return Futures.transform(input, rowFunction);
838 - DatabaseSchema dbSchema = FromJsonUtil 838 + }
839 - .jsonNodeToDbSchema(dbName, input); 839 + return null;
840 - if (dbSchema == null) { 840 + } else {
841 - log.debug("Get ovsdb database schema error"); 841 + return Futures.immediateFuture(databaseSchema);
842 - return null; 842 + }
843 - } 843 + }
844 - schema.put(dbName, dbSchema); 844 +
845 - 845 + @Override
846 - return dbSchema; 846 + public ListenableFuture<TableUpdates> monitorTables(String dbName, String id) {
847 - } 847 + if (dbName == null) {
848 - }; 848 + return null;
849 - 849 + }
850 - ListenableFuture<JsonNode> input = getSchema(dbNames); 850 + DatabaseSchema dbSchema = schema.get(dbName);
851 - if (input != null) { 851 + if (dbSchema != null) {
852 - try { 852 + Function<JsonNode, TableUpdates> rowFunction = new Function<JsonNode, TableUpdates>() {
853 - log.info("input message: {}", input.get().toString()); 853 + @Override
854 - } catch (InterruptedException e) { 854 + public TableUpdates apply(JsonNode input) {
855 - log.warn("Interrupted while waiting to get message"); 855 + log.info("Get table updates");
856 - Thread.currentThread().interrupt(); 856 + TableUpdates updates = FromJsonUtil
857 - } catch (ExecutionException e) { 857 + .jsonNodeToTableUpdates(input, dbSchema);
858 - log.error("Exception thrown while to get message"); 858 + if (updates == null) {
859 - } 859 + log.debug("Get table updates error");
860 - } 860 + return null;
861 - return Futures.transform(input, rowFunction); 861 + }
862 - } else { 862 + return updates;
863 - return Futures.immediateFuture(databaseSchema); 863 + }
864 - } 864 + };
865 - } 865 + return Futures.transform(monitor(dbSchema, id), rowFunction);
866 - 866 + }
867 - @Override 867 + return null;
868 - public ListenableFuture<TableUpdates> monitorTables(String dbName, String id) { 868 + }
869 - if (dbName == null) { 869 +
870 - return null; 870 + @Override
871 - } 871 + public ListenableFuture<List<OperationResult>> transactConfig(String dbName,
872 - DatabaseSchema dbSchema = schema.get(dbName); 872 + List<Operation> operations) {
873 - if (dbSchema != null) { 873 + if (dbName == null) {
874 - Function<JsonNode, TableUpdates> rowFunction = new Function<JsonNode, TableUpdates>() { 874 + return null;
875 - @Override 875 + }
876 - public TableUpdates apply(JsonNode input) { 876 + DatabaseSchema dbSchema = schema.get(dbName);
877 - log.info("Get table updates"); 877 + if (dbSchema != null) {
878 - TableUpdates updates = FromJsonUtil 878 + Function<List<JsonNode>, List<OperationResult>> rowFunction =
879 - .jsonNodeToTableUpdates(input, dbSchema); 879 + new Function<List<JsonNode>, List<OperationResult>>() {
880 - if (updates == null) { 880 + @Override
881 - log.debug("Get table updates error"); 881 + public List<OperationResult> apply(List<JsonNode> input) {
882 - return null; 882 + log.info("Get ovsdb operation result");
883 - } 883 + List<OperationResult> result = FromJsonUtil
884 - return updates; 884 + .jsonNodeToOperationResult(input, operations);
885 - } 885 +
886 - }; 886 + if (result == null) {
887 - return Futures.transform(monitor(dbSchema, id), rowFunction); 887 + log.debug("The operation result is null");
888 - } 888 + return null;
889 - return null; 889 + }
890 - } 890 + return result;
891 - 891 + }
892 - @Override 892 + };
893 - public ListenableFuture<List<OperationResult>> transactConfig(String dbName, 893 + return Futures.transform(transact(dbSchema, operations),
894 - List<Operation> operations) { 894 + rowFunction);
895 - if (dbName == null) { 895 + }
896 - return null; 896 + return null;
897 - } 897 + }
898 - DatabaseSchema dbSchema = schema.get(dbName); 898 +
899 - if (dbSchema != null) { 899 + @Override
900 - Function<List<JsonNode>, List<OperationResult>> rowFunction = 900 + public ListenableFuture<JsonNode> getSchema(List<String> dbnames) {
901 - new Function<List<JsonNode>, List<OperationResult>>() { 901 + String id = java.util.UUID.randomUUID().toString();
902 - @Override 902 + String getSchemaString = JsonRpcWriterUtil.getSchemaStr(id, dbnames);
903 - public List<OperationResult> apply(List<JsonNode> input) { 903 +
904 - log.info("Get ovsdb operation result"); 904 + SettableFuture<JsonNode> sf = SettableFuture.create();
905 - List<OperationResult> result = FromJsonUtil 905 + requestResult.put(id, sf);
906 - .jsonNodeToOperationResult(input, operations); 906 + requestMethod.put(id, "getSchema");
907 - 907 +
908 - if (result == null) { 908 + channel.writeAndFlush(getSchemaString);
909 - log.debug("The operation result is null"); 909 + return sf;
910 - return null; 910 +
911 - } 911 + }
912 - return result; 912 +
913 - } 913 + @Override
914 - }; 914 + public ListenableFuture<List<String>> echo() {
915 - return Futures.transform(transact(dbSchema, operations), 915 + String id = java.util.UUID.randomUUID().toString();
916 - rowFunction); 916 + String echoString = JsonRpcWriterUtil.echoStr(id);
917 - } 917 +
918 - return null; 918 + SettableFuture<List<String>> sf = SettableFuture.create();
919 - } 919 + requestResult.put(id, sf);
920 - 920 + requestMethod.put(id, "echo");
921 - @Override 921 +
922 - public ListenableFuture<JsonNode> getSchema(List<String> dbnames) { 922 + channel.writeAndFlush(echoString);
923 - String id = java.util.UUID.randomUUID().toString(); 923 + return sf;
924 - String getSchemaString = JsonRpcWriterUtil.getSchemaStr(id, dbnames); 924 +
925 - 925 + }
926 - SettableFuture<JsonNode> sf = SettableFuture.create(); 926 +
927 - requestResult.put(id, sf); 927 + @Override
928 - requestMethod.put(id, "getSchema"); 928 + public ListenableFuture<JsonNode> monitor(DatabaseSchema dbSchema,
929 - 929 + String monitorId) {
930 - channel.writeAndFlush(getSchemaString); 930 + String id = java.util.UUID.randomUUID().toString();
931 - return sf; 931 + String monitorString = JsonRpcWriterUtil.monitorStr(id, monitorId,
932 - 932 + dbSchema);
933 - } 933 +
934 - 934 + SettableFuture<JsonNode> sf = SettableFuture.create();
935 - @Override 935 + requestResult.put(id, sf);
936 - public ListenableFuture<List<String>> echo() { 936 + requestMethod.put(id, "monitor");
937 - String id = java.util.UUID.randomUUID().toString(); 937 +
938 - String echoString = JsonRpcWriterUtil.echoStr(id); 938 + channel.writeAndFlush(monitorString);
939 - 939 + return sf;
940 - SettableFuture<List<String>> sf = SettableFuture.create(); 940 +
941 - requestResult.put(id, sf); 941 + }
942 - requestMethod.put(id, "echo"); 942 +
943 - 943 + @Override
944 - channel.writeAndFlush(echoString); 944 + public ListenableFuture<List<String>> listDbs() {
945 - return sf; 945 + String id = java.util.UUID.randomUUID().toString();
946 - 946 + String listDbsString = JsonRpcWriterUtil.listDbsStr(id);
947 - } 947 +
948 - 948 + SettableFuture<List<String>> sf = SettableFuture.create();
949 - @Override 949 + requestResult.put(id, sf);
950 - public ListenableFuture<JsonNode> monitor(DatabaseSchema dbSchema, 950 + requestMethod.put(id, "listDbs");
951 - String monitorId) { 951 +
952 - String id = java.util.UUID.randomUUID().toString(); 952 + channel.writeAndFlush(listDbsString);
953 - String monitorString = JsonRpcWriterUtil.monitorStr(id, monitorId, 953 + return sf;
954 - dbSchema); 954 +
955 - 955 + }
956 - SettableFuture<JsonNode> sf = SettableFuture.create(); 956 +
957 - requestResult.put(id, sf); 957 + @Override
958 - requestMethod.put(id, "monitor"); 958 + public ListenableFuture<List<JsonNode>> transact(DatabaseSchema dbSchema,
959 - 959 + List<Operation> operations) {
960 - channel.writeAndFlush(monitorString); 960 + String id = java.util.UUID.randomUUID().toString();
961 - return sf; 961 + String transactString = JsonRpcWriterUtil.transactStr(id, dbSchema,
962 - 962 + operations);
963 - } 963 +
964 - 964 + SettableFuture<List<JsonNode>> sf = SettableFuture.create();
965 - @Override 965 + requestResult.put(id, sf);
966 - public ListenableFuture<List<String>> listDbs() { 966 + requestMethod.put(id, "transact");
967 - String id = java.util.UUID.randomUUID().toString(); 967 +
968 - String listDbsString = JsonRpcWriterUtil.listDbsStr(id); 968 + channel.writeAndFlush(transactString);
969 - 969 + return sf;
970 - SettableFuture<List<String>> sf = SettableFuture.create(); 970 +
971 - requestResult.put(id, sf); 971 + }
972 - requestMethod.put(id, "listDbs"); 972 +
973 - 973 + @SuppressWarnings({ "rawtypes", "unchecked" })
974 - channel.writeAndFlush(listDbsString); 974 + @Override
975 - return sf; 975 + public void processResult(JsonNode response) {
976 - 976 + log.debug("Handle result");
977 - } 977 + String requestId = response.get("id").asText();
978 - 978 + SettableFuture sf = requestResult.get(requestId);
979 - @Override 979 + if (sf == null) {
980 - public ListenableFuture<List<JsonNode>> transact(DatabaseSchema dbSchema, 980 + log.debug("No such future to process");
981 - List<Operation> operations) { 981 + return;
982 - String id = java.util.UUID.randomUUID().toString(); 982 + }
983 - String transactString = JsonRpcWriterUtil.transactStr(id, dbSchema, 983 + String methodName = requestMethod.get(requestId);
984 - operations); 984 +
985 - 985 + Object result;
986 - SettableFuture<List<JsonNode>> sf = SettableFuture.create(); 986 + result = FromJsonUtil.jsonResultParser(response, methodName);
987 - requestResult.put(id, sf); 987 +
988 - requestMethod.put(id, "transact"); 988 + sf.set(result);
989 - 989 + return;
990 - channel.writeAndFlush(transactString); 990 + }
991 - return sf; 991 +
992 - 992 + @Override
993 - } 993 + public void processRequest(JsonNode requestJson) {
994 - 994 + log.debug("Handle request");
995 - @SuppressWarnings({ "rawtypes", "unchecked" }) 995 + if (requestJson.get("method").asText().equalsIgnoreCase("echo")) {
996 - @Override 996 + log.debug("handle echo request");
997 - public void processResult(JsonNode response) { 997 +
998 - log.debug("Handle result"); 998 + String replyString = FromJsonUtil.getEchoRequestStr(requestJson);
999 - String requestId = response.get("id").asText(); 999 + channel.writeAndFlush(replyString);
1000 - SettableFuture sf = requestResult.get(requestId); 1000 +
1001 - if (sf == null) { 1001 + return;
1002 - log.debug("No such future to process"); 1002 + } else {
1003 - return; 1003 + FromJsonUtil
1004 - } 1004 + .jsonCallbackRequestParser(requestJson, monitorCallBack);
1005 - String methodName = requestMethod.get(requestId); 1005 + return;
1006 - 1006 + }
1007 - Object result; 1007 + }
1008 - result = FromJsonUtil.jsonResultParser(response, methodName); 1008 +
1009 - 1009 + @Override
1010 - sf.set(result); 1010 + public void setCallback(Callback monitorCallback) {
1011 - return; 1011 + this.monitorCallBack = monitorCallback;
1012 - } 1012 + }
1013 - 1013 +
1014 - @Override 1014 + @Override
1015 - public void processRequest(JsonNode requestJson) { 1015 + public Set<OvsdbTunnel> getTunnels() {
1016 - log.debug("Handle request"); 1016 + return ovsdbTunnels;
1017 - if (requestJson.get("method").asText().equalsIgnoreCase("echo")) { 1017 + }
1018 - log.debug("handle echo request"); 1018 +
1019 - 1019 + @Override
1020 - String replyString = FromJsonUtil.getEchoRequestStr(requestJson); 1020 + public Set<OvsdbBridge> getBridges() {
1021 - channel.writeAndFlush(replyString); 1021 + Set<OvsdbBridge> ovsdbBridges = new HashSet<OvsdbBridge>();
1022 - 1022 + OvsdbTableStore tableStore = getTableStore(OvsdbConstant.DATABASENAME);
1023 - return; 1023 + if (tableStore == null) {
1024 - } else { 1024 + return null;
1025 - FromJsonUtil 1025 + }
1026 - .jsonCallbackRequestParser(requestJson, monitorCallBack); 1026 + OvsdbRowStore rowStore = tableStore.getRows(OvsdbConstant.BRIDGE);
1027 - return; 1027 + if (rowStore == null) {
1028 - } 1028 + return null;
1029 - } 1029 + }
1030 - 1030 + ConcurrentMap<String, Row> rows = rowStore.getRowStore();
1031 - @Override 1031 + for (String uuid : rows.keySet()) {
1032 - public void setCallback(Callback monitorCallback) { 1032 + Row row = getRow(OvsdbConstant.DATABASENAME, OvsdbConstant.BRIDGE,
1033 - this.monitorCallBack = monitorCallback; 1033 + uuid);
1034 - } 1034 + OvsdbBridge ovsdbBridge = getOvsdbBridge(row);
1035 - 1035 + if (ovsdbBridge != null) {
1036 - @Override 1036 + ovsdbBridges.add(ovsdbBridge);
1037 - public Set<OvsdbTunnel> getTunnels() { 1037 + }
1038 - return ovsdbTunnels; 1038 + }
1039 - } 1039 + return ovsdbBridges;
1040 - 1040 + }
1041 - @Override 1041 +
1042 - public Set<OvsdbBridge> getBridges() { 1042 + @Override
1043 - return ovsdbBridges; 1043 + public Set<OvsdbPort> getPorts() {
1044 - } 1044 + Set<OvsdbPort> ovsdbPorts = new HashSet<OvsdbPort>();
1045 - 1045 + OvsdbTableStore tableStore = getTableStore(OvsdbConstant.DATABASENAME);
1046 - @Override 1046 + if (tableStore == null) {
1047 - public Set<OvsdbPort> getPorts() { 1047 + return null;
1048 - return ovsdbPorts; 1048 + }
1049 - } 1049 + OvsdbRowStore rowStore = tableStore.getRows(OvsdbConstant.INTERFACE);
1050 - 1050 + if (rowStore == null) {
1051 - @Override 1051 + return null;
1052 - public DatabaseSchema getDatabaseSchema(String dbName) { 1052 + }
1053 - return schema.get(dbName); 1053 + ConcurrentMap<String, Row> rows = rowStore.getRowStore();
1054 - } 1054 + for (String uuid : rows.keySet()) {
1055 - 1055 + Row row = getRow(OvsdbConstant.DATABASENAME,
1056 -} 1056 + OvsdbConstant.INTERFACE, uuid);
1057 + OvsdbPort ovsdbPort = getOvsdbPort(row);
1058 + if (ovsdbPort != null) {
1059 + ovsdbPorts.add(ovsdbPort);
1060 + }
1061 + }
1062 + return ovsdbPorts;
1063 + }
1064 +
1065 + @Override
1066 + public DatabaseSchema getDatabaseSchema(String dbName) {
1067 + return schema.get(dbName);
1068 + }
1069 +
1070 + //Gets ovsdb port.
1071 + private OvsdbPort getOvsdbPort(Row row) {
1072 + DatabaseSchema dbSchema = getDatabaseSchema(OvsdbConstant.DATABASENAME);
1073 + Interface intf = (Interface) TableGenerator
1074 + .getTable(dbSchema, row, OvsdbTable.INTERFACE);
1075 + if (intf == null) {
1076 + return null;
1077 + }
1078 + long ofPort = getOfPort(intf);
1079 + String portName = intf.getName();
1080 + if ((ofPort < 0) || (portName == null)) {
1081 + return null;
1082 + }
1083 +
1084 + OvsdbPort ovsdbPort = new OvsdbPort(new OvsdbPortNumber(ofPort),
1085 + new OvsdbPortName(portName));
1086 + return ovsdbPort;
1087 + }
1088 +
1089 + ////Gets ovsdb bridge.
1090 + private OvsdbBridge getOvsdbBridge(Row row) {
1091 + DatabaseSchema dbSchema = getDatabaseSchema(OvsdbConstant.DATABASENAME);
1092 + Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, row,
1093 + OvsdbTable.BRIDGE);
1094 + if (bridge == null) {
1095 + return null;
1096 + }
1097 +
1098 + OvsdbSet datapathIdSet = (OvsdbSet) bridge.getDatapathIdColumn().data();
1099 + @SuppressWarnings("unchecked")
1100 + Set<String> datapathIds = datapathIdSet.set();
1101 + if (datapathIds == null || datapathIds.size() == 0) {
1102 + return null;
1103 + }
1104 + String datapathId = (String) datapathIds.toArray()[0];
1105 + String bridgeName = bridge.getName();
1106 + if ((datapathId == null) || (bridgeName == null)) {
1107 + return null;
1108 + }
1109 +
1110 + OvsdbBridge ovsdbBridge = new OvsdbBridge(new OvsdbBridgeName(bridgeName),
1111 + new OvsdbDatapathId(datapathId));
1112 + return ovsdbBridge;
1113 + }
1114 +
1115 + //Gets ofPort in the interface.
1116 + private long getOfPort(Interface intf) {
1117 + OvsdbSet ofPortSet = (OvsdbSet) intf.getOpenFlowPortColumn().data();
1118 + @SuppressWarnings("unchecked")
1119 + Set<Integer> ofPorts = ofPortSet.set();
1120 + while (ofPorts == null || ofPorts.size() <= 0) {
1121 + log.debug("The ofport is null in {}", intf.getName());
1122 + return -1;
1123 + }
1124 + // return (long) ofPorts.toArray()[0];
1125 + Iterator<Integer> it = ofPorts.iterator();
1126 + return Long.parseLong(it.next().toString());
1127 + }
1128 +}
......