Committed by
Gerrit Code Review
ONOS-2708
Add implementation of getting ovsdb ports or bridges in the ovsdb node. Change-Id: If31af08ccb90a29bc800a79f332dae2bc497b105
Showing
4 changed files
with
154 additions
and
57 deletions
... | @@ -16,7 +16,9 @@ | ... | @@ -16,7 +16,9 @@ |
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 | +import java.util.Set; | ||
19 | 20 | ||
21 | +import org.onosproject.net.PortNumber; | ||
20 | import org.onosproject.net.device.PortDescription; | 22 | import org.onosproject.net.device.PortDescription; |
21 | import org.onosproject.net.driver.HandlerBehaviour; | 23 | import org.onosproject.net.driver.HandlerBehaviour; |
22 | 24 | ||
... | @@ -66,4 +68,11 @@ public interface BridgeConfig extends HandlerBehaviour { | ... | @@ -66,4 +68,11 @@ public interface BridgeConfig extends HandlerBehaviour { |
66 | * @return collection of port | 68 | * @return collection of port |
67 | */ | 69 | */ |
68 | Collection<PortDescription> getPorts(); | 70 | Collection<PortDescription> getPorts(); |
71 | + | ||
72 | + /** | ||
73 | + * Get a collection of port. | ||
74 | + * | ||
75 | + * @return portNumbers set of PortNumber | ||
76 | + */ | ||
77 | + Set<PortNumber> getPortNumbers(); | ||
69 | } | 78 | } | ... | ... |
... | @@ -16,6 +16,8 @@ | ... | @@ -16,6 +16,8 @@ |
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.Collections; | ||
20 | +import java.util.HashSet; | ||
19 | import java.util.Set; | 21 | import java.util.Set; |
20 | 22 | ||
21 | import org.onlab.packet.IpAddress; | 23 | import org.onlab.packet.IpAddress; |
... | @@ -46,45 +48,44 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour | ... | @@ -46,45 +48,44 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour |
46 | @Override | 48 | @Override |
47 | public void addBridge(BridgeName bridgeName) { | 49 | public void addBridge(BridgeName bridgeName) { |
48 | DriverHandler handler = handler(); | 50 | DriverHandler handler = handler(); |
49 | - OvsdbClientService ovsdbNode = getOvsdbNode(handler); | 51 | + OvsdbClientService clientService = getOvsdbClientService(handler); |
50 | - ovsdbNode.createBridge(bridgeName.name()); | 52 | + clientService.createBridge(bridgeName.name()); |
51 | } | 53 | } |
52 | 54 | ||
53 | @Override | 55 | @Override |
54 | public void deleteBridge(BridgeName bridgeName) { | 56 | public void deleteBridge(BridgeName bridgeName) { |
55 | DriverHandler handler = handler(); | 57 | DriverHandler handler = handler(); |
56 | - OvsdbClientService ovsdbNode = getOvsdbNode(handler); | 58 | + OvsdbClientService clientService = getOvsdbClientService(handler); |
57 | - ovsdbNode.dropBridge(bridgeName.name()); | 59 | + clientService.dropBridge(bridgeName.name()); |
58 | } | 60 | } |
59 | 61 | ||
60 | @Override | 62 | @Override |
61 | public Collection<BridgeDescription> getBridges() { | 63 | public Collection<BridgeDescription> getBridges() { |
62 | DriverHandler handler = handler(); | 64 | DriverHandler handler = handler(); |
63 | DeviceId deviceId = handler.data().deviceId(); | 65 | DeviceId deviceId = handler.data().deviceId(); |
64 | - OvsdbClientService ovsdbNode = getOvsdbNode(handler); | 66 | + OvsdbClientService clientService = getOvsdbClientService(handler); |
65 | - Set<OvsdbBridge> ovsdbSet = ovsdbNode.getBridges(); | 67 | + Set<OvsdbBridge> ovsdbSet = clientService.getBridges(); |
66 | Collection<BridgeDescription> bridges = Sets.newHashSet(); | 68 | Collection<BridgeDescription> bridges = Sets.newHashSet(); |
67 | ovsdbSet.forEach(o -> { | 69 | ovsdbSet.forEach(o -> { |
68 | - BridgeName bridgeName = BridgeName.bridgeName(o.bridgeName() | 70 | + BridgeName bridgeName = BridgeName |
69 | - .toString()); | 71 | + .bridgeName(o.bridgeName().value()); |
70 | - DeviceId ownDeviceId = DeviceId.deviceId(o.datapathId().toString()); | 72 | + DeviceId ownDeviceId = DeviceId.deviceId("of:" + o.datapathId().value()); |
71 | - BridgeDescription description = new DefaultBridgeDescription( | 73 | + BridgeDescription description = new DefaultBridgeDescription(bridgeName, |
72 | - bridgeName, | ||
73 | deviceId, | 74 | deviceId, |
74 | ownDeviceId); | 75 | ownDeviceId); |
75 | bridges.add(description); | 76 | bridges.add(description); |
76 | }); | 77 | }); |
77 | - return bridges; | 78 | + return bridges == null ? Collections.emptySet() : bridges; |
78 | } | 79 | } |
79 | 80 | ||
80 | @Override | 81 | @Override |
81 | public void addPort(PortDescription port) { | 82 | public void addPort(PortDescription port) { |
82 | DriverHandler handler = handler(); | 83 | DriverHandler handler = handler(); |
83 | - OvsdbClientService ovsdbNode = getOvsdbNode(handler); | 84 | + OvsdbClientService clientService = getOvsdbClientService(handler); |
84 | - Set<OvsdbBridge> ovsdbSet = ovsdbNode.getBridges(); | 85 | + Set<OvsdbBridge> ovsdbSet = clientService.getBridges(); |
85 | if (ovsdbSet != null && ovsdbSet.size() > 0) { | 86 | if (ovsdbSet != null && ovsdbSet.size() > 0) { |
86 | OvsdbBridge bridge = ovsdbSet.iterator().next(); | 87 | OvsdbBridge bridge = ovsdbSet.iterator().next(); |
87 | - ovsdbNode.createPort(bridge.bridgeName().toString(), port | 88 | + clientService.createPort(bridge.bridgeName().toString(), port |
88 | .portNumber().toString()); | 89 | .portNumber().toString()); |
89 | } | 90 | } |
90 | } | 91 | } |
... | @@ -92,11 +93,11 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour | ... | @@ -92,11 +93,11 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour |
92 | @Override | 93 | @Override |
93 | public void deletePort(PortDescription port) { | 94 | public void deletePort(PortDescription port) { |
94 | DriverHandler handler = handler(); | 95 | DriverHandler handler = handler(); |
95 | - OvsdbClientService ovsdbNode = getOvsdbNode(handler); | 96 | + OvsdbClientService clientService = getOvsdbClientService(handler); |
96 | - Set<OvsdbBridge> ovsdbSet = ovsdbNode.getBridges(); | 97 | + Set<OvsdbBridge> ovsdbSet = clientService.getBridges(); |
97 | if (ovsdbSet != null && ovsdbSet.size() > 0) { | 98 | if (ovsdbSet != null && ovsdbSet.size() > 0) { |
98 | OvsdbBridge bridge = ovsdbSet.iterator().next(); | 99 | OvsdbBridge bridge = ovsdbSet.iterator().next(); |
99 | - ovsdbNode.dropPort(bridge.bridgeName().toString(), port | 100 | + clientService.dropPort(bridge.bridgeName().toString(), port |
100 | .portNumber().toString()); | 101 | .portNumber().toString()); |
101 | } | 102 | } |
102 | } | 103 | } |
... | @@ -104,8 +105,8 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour | ... | @@ -104,8 +105,8 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour |
104 | @Override | 105 | @Override |
105 | public Collection<PortDescription> getPorts() { | 106 | public Collection<PortDescription> getPorts() { |
106 | DriverHandler handler = handler(); | 107 | DriverHandler handler = handler(); |
107 | - OvsdbClientService ovsdbNode = getOvsdbNode(handler); | 108 | + OvsdbClientService clientService = getOvsdbClientService(handler); |
108 | - Set<OvsdbPort> ovsdbSet = ovsdbNode.getPorts(); | 109 | + Set<OvsdbPort> ovsdbSet = clientService.getPorts(); |
109 | Collection<PortDescription> ports = Sets.newHashSet(); | 110 | Collection<PortDescription> ports = Sets.newHashSet(); |
110 | ovsdbSet.forEach(o -> { | 111 | ovsdbSet.forEach(o -> { |
111 | PortNumber port = PortNumber.portNumber(o.portNumber().value()); | 112 | PortNumber port = PortNumber.portNumber(o.portNumber().value()); |
... | @@ -127,10 +128,25 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour | ... | @@ -127,10 +128,25 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour |
127 | return new OvsdbNodeId(ipAddress, portL); | 128 | return new OvsdbNodeId(ipAddress, portL); |
128 | } | 129 | } |
129 | 130 | ||
130 | - private OvsdbClientService getOvsdbNode(DriverHandler handler) { | 131 | + // Used for getting OvsdbClientService. |
132 | + private OvsdbClientService getOvsdbClientService(DriverHandler handler) { | ||
131 | OvsdbController ovsController = handler.get(OvsdbController.class); | 133 | OvsdbController ovsController = handler.get(OvsdbController.class); |
132 | DeviceId deviceId = handler.data().deviceId(); | 134 | DeviceId deviceId = handler.data().deviceId(); |
133 | OvsdbNodeId nodeId = changeDeviceIdToNodeId(deviceId); | 135 | OvsdbNodeId nodeId = changeDeviceIdToNodeId(deviceId); |
134 | return ovsController.getOvsdbClient(nodeId); | 136 | return ovsController.getOvsdbClient(nodeId); |
135 | } | 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 | + } | ||
136 | } | 152 | } | ... | ... |
... | @@ -18,18 +18,18 @@ | ... | @@ -18,18 +18,18 @@ |
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 | + <behaviour api="org.onosproject.net.behaviour.TunnelConfig" | ||
25 | + impl="org.onosproject.driver.ovsdb.OvsdbTunnelConfig"/> | ||
26 | + <behaviour api="org.onosproject.net.behaviour.BridgeConfig" | ||
27 | + impl="org.onosproject.driver.ovsdb.OvsdbBridgeConfig"/> | ||
24 | </driver> | 28 | </driver> |
25 | <driver name="ovs" extends="default" | 29 | <driver name="ovs" extends="default" |
26 | manufacturer="Nicira, Inc\." hwVersion="Open vSwitch" swVersion="2\..*"> | 30 | manufacturer="Nicira, Inc\." hwVersion="Open vSwitch" swVersion="2\..*"> |
27 | <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" | 31 | <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" |
28 | impl="org.onosproject.driver.handshaker.NiciraSwitchHandshaker"/> | 32 | impl="org.onosproject.driver.handshaker.NiciraSwitchHandshaker"/> |
29 | - <behaviour api="org.onosproject.net.behaviour.TunnelConfig" | ||
30 | - impl="org.onosproject.driver.ovsdb.OvsdbTunnelConfig"/> | ||
31 | - <behaviour api="org.onosproject.net.behaviour.BridgeConfig" | ||
32 | - impl="org.onosproject.driver.ovsdb.OvsdbBridgeConfig"/> | ||
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"> | ... | ... |
... | @@ -20,6 +20,7 @@ import io.netty.channel.Channel; | ... | @@ -20,6 +20,7 @@ import io.netty.channel.Channel; |
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.Iterator; | ||
23 | import java.util.List; | 24 | import java.util.List; |
24 | import java.util.Map; | 25 | import java.util.Map; |
25 | import java.util.Set; | 26 | import java.util.Set; |
... | @@ -28,10 +29,14 @@ import java.util.concurrent.ExecutionException; | ... | @@ -28,10 +29,14 @@ import java.util.concurrent.ExecutionException; |
28 | 29 | ||
29 | import org.onlab.packet.IpAddress; | 30 | import org.onlab.packet.IpAddress; |
30 | import org.onosproject.ovsdb.controller.OvsdbBridge; | 31 | import org.onosproject.ovsdb.controller.OvsdbBridge; |
32 | +import org.onosproject.ovsdb.controller.OvsdbBridgeName; | ||
31 | import org.onosproject.ovsdb.controller.OvsdbClientService; | 33 | import org.onosproject.ovsdb.controller.OvsdbClientService; |
32 | import org.onosproject.ovsdb.controller.OvsdbConstant; | 34 | import org.onosproject.ovsdb.controller.OvsdbConstant; |
35 | +import org.onosproject.ovsdb.controller.OvsdbDatapathId; | ||
33 | import org.onosproject.ovsdb.controller.OvsdbNodeId; | 36 | import org.onosproject.ovsdb.controller.OvsdbNodeId; |
34 | import org.onosproject.ovsdb.controller.OvsdbPort; | 37 | import org.onosproject.ovsdb.controller.OvsdbPort; |
38 | +import org.onosproject.ovsdb.controller.OvsdbPortName; | ||
39 | +import org.onosproject.ovsdb.controller.OvsdbPortNumber; | ||
35 | import org.onosproject.ovsdb.controller.OvsdbRowStore; | 40 | import org.onosproject.ovsdb.controller.OvsdbRowStore; |
36 | import org.onosproject.ovsdb.controller.OvsdbStore; | 41 | import org.onosproject.ovsdb.controller.OvsdbStore; |
37 | import org.onosproject.ovsdb.controller.OvsdbTableStore; | 42 | import org.onosproject.ovsdb.controller.OvsdbTableStore; |
... | @@ -96,9 +101,7 @@ public class DefaultOvsdbClient | ... | @@ -96,9 +101,7 @@ public class DefaultOvsdbClient |
96 | .newHashMap(); | 101 | .newHashMap(); |
97 | 102 | ||
98 | private final Map<String, DatabaseSchema> schema = Maps.newHashMap(); | 103 | private final Map<String, DatabaseSchema> schema = Maps.newHashMap(); |
99 | - private final Set<OvsdbPort> ovsdbPorts = new HashSet<OvsdbPort>(); | ||
100 | private final Set<OvsdbTunnel> ovsdbTunnels = new HashSet<OvsdbTunnel>(); | 104 | private final Set<OvsdbTunnel> ovsdbTunnels = new HashSet<OvsdbTunnel>(); |
101 | - private final Set<OvsdbBridge> ovsdbBridges = new HashSet<OvsdbBridge>(); | ||
102 | 105 | ||
103 | /** | 106 | /** |
104 | * Creates an OvsdbClient. | 107 | * Creates an OvsdbClient. |
... | @@ -247,9 +250,6 @@ public class DefaultOvsdbClient | ... | @@ -247,9 +250,6 @@ public class DefaultOvsdbClient |
247 | for (UUID uuid : ports) { | 250 | for (UUID uuid : ports) { |
248 | Row portRow = getRow(OvsdbConstant.DATABASENAME, | 251 | Row portRow = getRow(OvsdbConstant.DATABASENAME, |
249 | OvsdbConstant.PORT, uuid.value()); | 252 | OvsdbConstant.PORT, uuid.value()); |
250 | - if (portRow == null) { | ||
251 | - continue; | ||
252 | - } | ||
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())) { |
... | @@ -283,9 +283,6 @@ public class DefaultOvsdbClient | ... | @@ -283,9 +283,6 @@ public class DefaultOvsdbClient |
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) { | ||
287 | - continue; | ||
288 | - } | ||
289 | Interface intf = (Interface) TableGenerator | 286 | Interface intf = (Interface) TableGenerator |
290 | .getTable(dbSchema, intfRow, OvsdbTable.INTERFACE); | 287 | .getTable(dbSchema, intfRow, OvsdbTable.INTERFACE); |
291 | if (intf != null && portName.equalsIgnoreCase(intf.getName())) { | 288 | if (intf != null && portName.equalsIgnoreCase(intf.getName())) { |
... | @@ -583,22 +580,10 @@ public class DefaultOvsdbClient | ... | @@ -583,22 +580,10 @@ public class DefaultOvsdbClient |
583 | } | 580 | } |
584 | 581 | ||
585 | if (interfaceUuid != null) { | 582 | if (interfaceUuid != null) { |
586 | - OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME, | ||
587 | - OvsdbConstant.INTERFACE); | ||
588 | - if (rowStore == null) { | ||
589 | - log.debug("The bridge uuid is null"); | ||
590 | - return; | ||
591 | - } | ||
592 | - | ||
593 | - ConcurrentMap<String, Row> intfTableRows = rowStore.getRowStore(); | ||
594 | - if (intfTableRows == null) { | ||
595 | - log.debug("The bridge uuid is null"); | ||
596 | - return; | ||
597 | - } | ||
598 | 583 | ||
599 | Interface tunInterface = (Interface) TableGenerator | 584 | Interface tunInterface = (Interface) TableGenerator |
600 | - .getTable(dbSchema, intfTableRows.get(interfaceUuid), | 585 | + .createTable(dbSchema, OvsdbTable.INTERFACE); |
601 | - OvsdbTable.INTERFACE); | 586 | + |
602 | if (tunInterface != null) { | 587 | if (tunInterface != null) { |
603 | 588 | ||
604 | tunInterface.setType(OvsdbConstant.TYPEVXLAN); | 589 | tunInterface.setType(OvsdbConstant.TYPEVXLAN); |
... | @@ -849,16 +834,9 @@ public class DefaultOvsdbClient | ... | @@ -849,16 +834,9 @@ public class DefaultOvsdbClient |
849 | 834 | ||
850 | ListenableFuture<JsonNode> input = getSchema(dbNames); | 835 | ListenableFuture<JsonNode> input = getSchema(dbNames); |
851 | if (input != null) { | 836 | if (input != null) { |
852 | - try { | ||
853 | - log.info("input message: {}", input.get().toString()); | ||
854 | - } catch (InterruptedException e) { | ||
855 | - log.warn("Interrupted while waiting to get message"); | ||
856 | - Thread.currentThread().interrupt(); | ||
857 | - } catch (ExecutionException e) { | ||
858 | - log.error("Exception thrown while to get message"); | ||
859 | - } | ||
860 | - } | ||
861 | return Futures.transform(input, rowFunction); | 837 | return Futures.transform(input, rowFunction); |
838 | + } | ||
839 | + return null; | ||
862 | } else { | 840 | } else { |
863 | return Futures.immediateFuture(databaseSchema); | 841 | return Futures.immediateFuture(databaseSchema); |
864 | } | 842 | } |
... | @@ -1040,11 +1018,47 @@ public class DefaultOvsdbClient | ... | @@ -1040,11 +1018,47 @@ public class DefaultOvsdbClient |
1040 | 1018 | ||
1041 | @Override | 1019 | @Override |
1042 | public Set<OvsdbBridge> getBridges() { | 1020 | public Set<OvsdbBridge> getBridges() { |
1021 | + Set<OvsdbBridge> ovsdbBridges = new HashSet<OvsdbBridge>(); | ||
1022 | + OvsdbTableStore tableStore = getTableStore(OvsdbConstant.DATABASENAME); | ||
1023 | + if (tableStore == null) { | ||
1024 | + return null; | ||
1025 | + } | ||
1026 | + OvsdbRowStore rowStore = tableStore.getRows(OvsdbConstant.BRIDGE); | ||
1027 | + if (rowStore == null) { | ||
1028 | + return null; | ||
1029 | + } | ||
1030 | + ConcurrentMap<String, Row> rows = rowStore.getRowStore(); | ||
1031 | + for (String uuid : rows.keySet()) { | ||
1032 | + Row row = getRow(OvsdbConstant.DATABASENAME, OvsdbConstant.BRIDGE, | ||
1033 | + uuid); | ||
1034 | + OvsdbBridge ovsdbBridge = getOvsdbBridge(row); | ||
1035 | + if (ovsdbBridge != null) { | ||
1036 | + ovsdbBridges.add(ovsdbBridge); | ||
1037 | + } | ||
1038 | + } | ||
1043 | return ovsdbBridges; | 1039 | return ovsdbBridges; |
1044 | } | 1040 | } |
1045 | 1041 | ||
1046 | @Override | 1042 | @Override |
1047 | public Set<OvsdbPort> getPorts() { | 1043 | public Set<OvsdbPort> getPorts() { |
1044 | + Set<OvsdbPort> ovsdbPorts = new HashSet<OvsdbPort>(); | ||
1045 | + OvsdbTableStore tableStore = getTableStore(OvsdbConstant.DATABASENAME); | ||
1046 | + if (tableStore == null) { | ||
1047 | + return null; | ||
1048 | + } | ||
1049 | + OvsdbRowStore rowStore = tableStore.getRows(OvsdbConstant.INTERFACE); | ||
1050 | + if (rowStore == null) { | ||
1051 | + return null; | ||
1052 | + } | ||
1053 | + ConcurrentMap<String, Row> rows = rowStore.getRowStore(); | ||
1054 | + for (String uuid : rows.keySet()) { | ||
1055 | + Row row = getRow(OvsdbConstant.DATABASENAME, | ||
1056 | + OvsdbConstant.INTERFACE, uuid); | ||
1057 | + OvsdbPort ovsdbPort = getOvsdbPort(row); | ||
1058 | + if (ovsdbPort != null) { | ||
1059 | + ovsdbPorts.add(ovsdbPort); | ||
1060 | + } | ||
1061 | + } | ||
1048 | return ovsdbPorts; | 1062 | return ovsdbPorts; |
1049 | } | 1063 | } |
1050 | 1064 | ||
... | @@ -1053,4 +1067,62 @@ public class DefaultOvsdbClient | ... | @@ -1053,4 +1067,62 @@ public class DefaultOvsdbClient |
1053 | return schema.get(dbName); | 1067 | return schema.get(dbName); |
1054 | } | 1068 | } |
1055 | 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 | + } | ||
1056 | } | 1128 | } | ... | ... |
-
Please register or login to post a comment