Committed by
Gerrit Code Review
CORD-524 Added a state to set data plane IP to br-int
Added new config fields - SSH port, user, private key file - localManagementIp for connection b/w a compute node and VM Renamed some config fields and methods - phyPortName is changed to dataPlaneIntf - localIp is changed to dataPlaneIp - ovsdbIp is changed to hostManagementIp and it is used to SSH as well - checkXXX methods with boolean return are renamed to isXXX Removed unnecessary OVSDB_CONNECTED state Removed cordvtn-node-add CLI due to too many arguments Change-Id: If5efb65fc58bfa8a10767047f01598dc2ac02a04
Showing
10 changed files
with
377 additions
and
225 deletions
... | @@ -265,7 +265,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro | ... | @@ -265,7 +265,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro |
265 | SparseAnnotations annotations = DefaultAnnotations.builder() | 265 | SparseAnnotations annotations = DefaultAnnotations.builder() |
266 | .set(OPENSTACK_VM_ID, vPort.deviceId()) | 266 | .set(OPENSTACK_VM_ID, vPort.deviceId()) |
267 | .set(SERVICE_ID, vPort.networkId()) | 267 | .set(SERVICE_ID, vPort.networkId()) |
268 | - .set(LOCATION_IP, node.localIp().toString()) | 268 | + .set(LOCATION_IP, node.dpIp().ip().toString()) |
269 | .build(); | 269 | .build(); |
270 | 270 | ||
271 | HostDescription hostDesc = new DefaultHostDescription( | 271 | HostDescription hostDesc = new DefaultHostDescription( | ... | ... |
... | @@ -17,7 +17,6 @@ package org.onosproject.cordvtn; | ... | @@ -17,7 +17,6 @@ package org.onosproject.cordvtn; |
17 | 17 | ||
18 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
19 | import com.google.common.collect.Sets; | 19 | import com.google.common.collect.Sets; |
20 | -import org.onlab.packet.IpAddress; | ||
21 | import org.onlab.packet.MacAddress; | 20 | import org.onlab.packet.MacAddress; |
22 | import org.onlab.packet.TpPort; | 21 | import org.onlab.packet.TpPort; |
23 | import org.onosproject.core.ApplicationId; | 22 | import org.onosproject.core.ApplicationId; |
... | @@ -37,14 +36,19 @@ public class CordVtnConfig extends Config<ApplicationId> { | ... | @@ -37,14 +36,19 @@ public class CordVtnConfig extends Config<ApplicationId> { |
37 | 36 | ||
38 | protected final Logger log = getLogger(getClass()); | 37 | protected final Logger log = getLogger(getClass()); |
39 | 38 | ||
39 | + public static final String GATEWAY_MAC = "gatewayMac"; | ||
40 | + public static final String LOCAL_MANAGEMENT_IP = "localManagementIp"; | ||
41 | + public static final String OVSDB_PORT = "ovsdbPort"; | ||
42 | + public static final String SSH_PORT = "sshPort"; | ||
43 | + public static final String SSH_USER = "sshUser"; | ||
44 | + public static final String SSH_KEY_FILE = "sshKeyFile"; | ||
40 | public static final String CORDVTN_NODES = "nodes"; | 45 | public static final String CORDVTN_NODES = "nodes"; |
46 | + | ||
41 | public static final String HOSTNAME = "hostname"; | 47 | public static final String HOSTNAME = "hostname"; |
42 | - public static final String OVSDB_IP = "ovsdbIp"; | 48 | + public static final String HOST_MANAGEMENT_IP = "hostManagementIp"; |
43 | - public static final String OVSDB_PORT = "ovsdbPort"; | 49 | + public static final String DATA_PLANE_IP = "dataPlaneIp"; |
50 | + public static final String DATA_PLANE_INTF = "dataPlaneIntf"; | ||
44 | public static final String BRIDGE_ID = "bridgeId"; | 51 | public static final String BRIDGE_ID = "bridgeId"; |
45 | - public static final String PHYSICAL_PORT_NAME = "phyPortName"; | ||
46 | - public static final String LOCAL_IP = "localIp"; | ||
47 | - public static final String GATEWAY_MAC = "gatewayMac"; | ||
48 | 52 | ||
49 | /** | 53 | /** |
50 | * Returns the set of nodes read from network config. | 54 | * Returns the set of nodes read from network config. |
... | @@ -58,13 +62,19 @@ public class CordVtnConfig extends Config<ApplicationId> { | ... | @@ -58,13 +62,19 @@ public class CordVtnConfig extends Config<ApplicationId> { |
58 | if (jsonNodes == null) { | 62 | if (jsonNodes == null) { |
59 | return null; | 63 | return null; |
60 | } | 64 | } |
61 | - jsonNodes.forEach(jsonNode -> nodes.add(new CordVtnNodeConfig( | 65 | + |
66 | + jsonNodes.forEach(jsonNode -> { | ||
67 | + try { | ||
68 | + nodes.add(new CordVtnNodeConfig( | ||
62 | jsonNode.path(HOSTNAME).asText(), | 69 | jsonNode.path(HOSTNAME).asText(), |
63 | - IpAddress.valueOf(jsonNode.path(OVSDB_IP).asText()), | 70 | + NetworkAddress.valueOf(jsonNode.path(HOST_MANAGEMENT_IP).asText()), |
64 | - TpPort.tpPort(jsonNode.path(OVSDB_PORT).asInt()), | 71 | + NetworkAddress.valueOf(jsonNode.path(DATA_PLANE_IP).asText()), |
65 | - DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()), | 72 | + jsonNode.path(DATA_PLANE_INTF).asText(), |
66 | - jsonNode.path(PHYSICAL_PORT_NAME).asText(), | 73 | + DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()))); |
67 | - IpAddress.valueOf(jsonNode.path(LOCAL_IP).asText())))); | 74 | + } catch (IllegalArgumentException | NullPointerException e) { |
75 | + log.error("Failed to read {}", e.toString()); | ||
76 | + } | ||
77 | + }); | ||
68 | 78 | ||
69 | return nodes; | 79 | return nodes; |
70 | } | 80 | } |
... | @@ -89,25 +99,108 @@ public class CordVtnConfig extends Config<ApplicationId> { | ... | @@ -89,25 +99,108 @@ public class CordVtnConfig extends Config<ApplicationId> { |
89 | } | 99 | } |
90 | 100 | ||
91 | /** | 101 | /** |
102 | + * Returns local management network address. | ||
103 | + * | ||
104 | + * @return network address | ||
105 | + */ | ||
106 | + public NetworkAddress localMgmtIp() { | ||
107 | + JsonNode jsonNode = object.get(LOCAL_MANAGEMENT_IP); | ||
108 | + if (jsonNode == null) { | ||
109 | + return null; | ||
110 | + } | ||
111 | + | ||
112 | + try { | ||
113 | + return NetworkAddress.valueOf(jsonNode.asText()); | ||
114 | + } catch (IllegalArgumentException e) { | ||
115 | + log.error("Wrong address format {}", jsonNode.asText()); | ||
116 | + return null; | ||
117 | + } | ||
118 | + } | ||
119 | + | ||
120 | + /** | ||
121 | + * Returns the port number used for OVSDB connection. | ||
122 | + * | ||
123 | + * @return port number, or null | ||
124 | + */ | ||
125 | + public TpPort ovsdbPort() { | ||
126 | + JsonNode jsonNode = object.get(OVSDB_PORT); | ||
127 | + if (jsonNode == null) { | ||
128 | + return null; | ||
129 | + } | ||
130 | + | ||
131 | + try { | ||
132 | + return TpPort.tpPort(jsonNode.asInt()); | ||
133 | + } catch (IllegalArgumentException e) { | ||
134 | + log.error("Wrong TCP port format {}", jsonNode.asText()); | ||
135 | + return null; | ||
136 | + } | ||
137 | + } | ||
138 | + | ||
139 | + /** | ||
140 | + * Returns the port number used for SSH connection. | ||
141 | + * | ||
142 | + * @return port number, or null | ||
143 | + */ | ||
144 | + public TpPort sshPort() { | ||
145 | + JsonNode jsonNode = object.get(SSH_PORT); | ||
146 | + if (jsonNode == null) { | ||
147 | + return null; | ||
148 | + } | ||
149 | + | ||
150 | + try { | ||
151 | + return TpPort.tpPort(jsonNode.asInt()); | ||
152 | + } catch (IllegalArgumentException e) { | ||
153 | + log.error("Wrong TCP port format {}", jsonNode.asText()); | ||
154 | + return null; | ||
155 | + } | ||
156 | + } | ||
157 | + | ||
158 | + /** | ||
159 | + * Returns the user name for SSH connection. | ||
160 | + * | ||
161 | + * @return user name, or null | ||
162 | + */ | ||
163 | + public String sshUser() { | ||
164 | + JsonNode jsonNode = object.get(SSH_USER); | ||
165 | + if (jsonNode == null) { | ||
166 | + return null; | ||
167 | + } | ||
168 | + | ||
169 | + return jsonNode.asText(); | ||
170 | + } | ||
171 | + | ||
172 | + /** | ||
173 | + * Returns the private key file for SSH connection. | ||
174 | + * | ||
175 | + * @return file path, or null | ||
176 | + */ | ||
177 | + public String sshKeyFile() { | ||
178 | + JsonNode jsonNode = object.get(SSH_KEY_FILE); | ||
179 | + if (jsonNode == null) { | ||
180 | + return null; | ||
181 | + } | ||
182 | + | ||
183 | + return jsonNode.asText(); | ||
184 | + } | ||
185 | + | ||
186 | + /** | ||
92 | * Configuration for CordVtn node. | 187 | * Configuration for CordVtn node. |
93 | */ | 188 | */ |
94 | public static class CordVtnNodeConfig { | 189 | public static class CordVtnNodeConfig { |
95 | 190 | ||
96 | private final String hostname; | 191 | private final String hostname; |
97 | - private final IpAddress ovsdbIp; | 192 | + private final NetworkAddress hostMgmtIp; |
98 | - private final TpPort ovsdbPort; | 193 | + private final NetworkAddress dpIp; |
194 | + private final String dpIntf; | ||
99 | private final DeviceId bridgeId; | 195 | private final DeviceId bridgeId; |
100 | - private final String phyPortName; | ||
101 | - private final IpAddress localIp; | ||
102 | 196 | ||
103 | - public CordVtnNodeConfig(String hostname, IpAddress ovsdbIp, TpPort ovsdbPort, | 197 | + public CordVtnNodeConfig(String hostname, NetworkAddress hostMgmtIp, NetworkAddress dpIp, |
104 | - DeviceId bridgeId, String phyPortName, IpAddress localIp) { | 198 | + String dpIntf, DeviceId bridgeId) { |
105 | this.hostname = checkNotNull(hostname); | 199 | this.hostname = checkNotNull(hostname); |
106 | - this.ovsdbIp = checkNotNull(ovsdbIp); | 200 | + this.hostMgmtIp = checkNotNull(hostMgmtIp); |
107 | - this.ovsdbPort = checkNotNull(ovsdbPort); | 201 | + this.dpIp = checkNotNull(dpIp); |
202 | + this.dpIntf = checkNotNull(dpIntf); | ||
108 | this.bridgeId = checkNotNull(bridgeId); | 203 | this.bridgeId = checkNotNull(bridgeId); |
109 | - this.phyPortName = checkNotNull(phyPortName); | ||
110 | - this.localIp = checkNotNull(localIp); | ||
111 | } | 204 | } |
112 | 205 | ||
113 | /** | 206 | /** |
... | @@ -120,48 +213,39 @@ public class CordVtnConfig extends Config<ApplicationId> { | ... | @@ -120,48 +213,39 @@ public class CordVtnConfig extends Config<ApplicationId> { |
120 | } | 213 | } |
121 | 214 | ||
122 | /** | 215 | /** |
123 | - * Returns OVSDB ip address of the node. | 216 | + * Returns the host management network address of the node. |
124 | - * | ||
125 | - * @return OVSDB server IP address | ||
126 | - */ | ||
127 | - public IpAddress ovsdbIp() { | ||
128 | - return this.ovsdbIp; | ||
129 | - } | ||
130 | - | ||
131 | - /** | ||
132 | - * Returns OVSDB port number of the node. | ||
133 | * | 217 | * |
134 | - * @return port number | 218 | + * @return management network address |
135 | */ | 219 | */ |
136 | - public TpPort ovsdbPort() { | 220 | + public NetworkAddress hostMgmtIp() { |
137 | - return this.ovsdbPort; | 221 | + return this.hostMgmtIp; |
138 | } | 222 | } |
139 | 223 | ||
140 | /** | 224 | /** |
141 | - * Returns integration bridge id of the node. | 225 | + * Returns the data plane network address. |
142 | * | 226 | * |
143 | - * @return device id | 227 | + * @return network address |
144 | */ | 228 | */ |
145 | - public DeviceId bridgeId() { | 229 | + public NetworkAddress dpIp() { |
146 | - return this.bridgeId; | 230 | + return this.dpIp; |
147 | } | 231 | } |
148 | 232 | ||
149 | /** | 233 | /** |
150 | - * Returns physical port name. | 234 | + * Returns the data plane interface name. |
151 | * | 235 | * |
152 | - * @return physical port name | 236 | + * @return interface name |
153 | */ | 237 | */ |
154 | - public String phyPortName() { | 238 | + public String dpIntf() { |
155 | - return this.phyPortName; | 239 | + return this.dpIntf; |
156 | } | 240 | } |
157 | 241 | ||
158 | /** | 242 | /** |
159 | - * Returns local IP address. | 243 | + * Returns integration bridge id of the node. |
160 | * | 244 | * |
161 | - * @return ip address | 245 | + * @return device id |
162 | */ | 246 | */ |
163 | - public IpAddress localIp() { | 247 | + public DeviceId bridgeId() { |
164 | - return this.localIp; | 248 | + return this.bridgeId; |
165 | } | 249 | } |
166 | } | 250 | } |
167 | } | 251 | } | ... | ... |
... | @@ -16,7 +16,6 @@ | ... | @@ -16,7 +16,6 @@ |
16 | package org.onosproject.cordvtn; | 16 | package org.onosproject.cordvtn; |
17 | 17 | ||
18 | import com.google.common.base.MoreObjects; | 18 | import com.google.common.base.MoreObjects; |
19 | -import org.onlab.packet.IpAddress; | ||
20 | import org.onlab.packet.TpPort; | 19 | import org.onlab.packet.TpPort; |
21 | import org.onosproject.net.DeviceId; | 20 | import org.onosproject.net.DeviceId; |
22 | 21 | ||
... | @@ -31,11 +30,13 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -31,11 +30,13 @@ import static com.google.common.base.Preconditions.checkNotNull; |
31 | public final class CordVtnNode { | 30 | public final class CordVtnNode { |
32 | 31 | ||
33 | private final String hostname; | 32 | private final String hostname; |
34 | - private final IpAddress ovsdbIp; | 33 | + private final NetworkAddress hostMgmtIp; |
34 | + private final NetworkAddress localMgmtIp; | ||
35 | + private final NetworkAddress dpIp; | ||
35 | private final TpPort ovsdbPort; | 36 | private final TpPort ovsdbPort; |
37 | + private final SshAccessInfo sshInfo; | ||
36 | private final DeviceId bridgeId; | 38 | private final DeviceId bridgeId; |
37 | - private final String phyPortName; | 39 | + private final String dpIntf; |
38 | - private final IpAddress localIp; | ||
39 | 40 | ||
40 | public static final Comparator<CordVtnNode> CORDVTN_NODE_COMPARATOR = | 41 | public static final Comparator<CordVtnNode> CORDVTN_NODE_COMPARATOR = |
41 | (node1, node2) -> node1.hostname().compareTo(node2.hostname()); | 42 | (node1, node2) -> node1.hostname().compareTo(node2.hostname()); |
... | @@ -44,33 +45,65 @@ public final class CordVtnNode { | ... | @@ -44,33 +45,65 @@ public final class CordVtnNode { |
44 | * Creates a new node. | 45 | * Creates a new node. |
45 | * | 46 | * |
46 | * @param hostname hostname | 47 | * @param hostname hostname |
47 | - * @param ovsdbIp OVSDB server IP address | 48 | + * @param hostMgmtIp host management network address |
48 | - * @param ovsdbPort OVSDB server port number | 49 | + * @param localMgmtIp local management network address |
50 | + * @param dpIp data plane network address | ||
51 | + * @param ovsdbPort port number for OVSDB connection | ||
52 | + * @param sshInfo SSH access information | ||
49 | * @param bridgeId integration bridge identifier | 53 | * @param bridgeId integration bridge identifier |
50 | - * @param phyPortName physical port name | 54 | + * @param dpIntf data plane interface name |
51 | - * @param localIp local ip address of data plane | ||
52 | */ | 55 | */ |
53 | - public CordVtnNode(String hostname, IpAddress ovsdbIp, TpPort ovsdbPort, | 56 | + public CordVtnNode(String hostname, NetworkAddress hostMgmtIp, NetworkAddress localMgmtIp, |
54 | - DeviceId bridgeId, String phyPortName, IpAddress localIp) { | 57 | + NetworkAddress dpIp, TpPort ovsdbPort, SshAccessInfo sshInfo, |
55 | - this.hostname = checkNotNull(hostname); | 58 | + DeviceId bridgeId, String dpIntf) { |
56 | - this.ovsdbIp = checkNotNull(ovsdbIp); | 59 | + this.hostname = checkNotNull(hostname, "hostname cannot be null"); |
57 | - this.ovsdbPort = checkNotNull(ovsdbPort); | 60 | + this.hostMgmtIp = checkNotNull(hostMgmtIp, "hostMgmtIp cannot be null"); |
58 | - this.bridgeId = checkNotNull(bridgeId); | 61 | + this.localMgmtIp = checkNotNull(localMgmtIp, "localMgmtIp cannot be null"); |
59 | - this.phyPortName = checkNotNull(phyPortName); | 62 | + this.dpIp = checkNotNull(dpIp, "dpIp cannot be null"); |
60 | - this.localIp = checkNotNull(localIp); | 63 | + this.ovsdbPort = checkNotNull(ovsdbPort, "ovsdbPort cannot be null"); |
64 | + this.sshInfo = checkNotNull(sshInfo, "sshInfo cannot be null"); | ||
65 | + this.bridgeId = checkNotNull(bridgeId, "bridgeId cannot be null"); | ||
66 | + this.dpIntf = checkNotNull(dpIntf, "dpIntf cannot be null"); | ||
61 | } | 67 | } |
62 | 68 | ||
63 | /** | 69 | /** |
64 | - * Returns the OVSDB server IP address. | 70 | + * Returns the hostname. |
71 | + * | ||
72 | + * @return hostname | ||
73 | + */ | ||
74 | + public String hostname() { | ||
75 | + return this.hostname; | ||
76 | + } | ||
77 | + | ||
78 | + /** | ||
79 | + * Returns the host management network address. | ||
80 | + * | ||
81 | + * @return network address | ||
82 | + */ | ||
83 | + public NetworkAddress hostMgmtIp() { | ||
84 | + return this.hostMgmtIp; | ||
85 | + } | ||
86 | + | ||
87 | + /** | ||
88 | + * Returns the local management network address. | ||
65 | * | 89 | * |
66 | - * @return ip address | 90 | + * @return network address |
67 | */ | 91 | */ |
68 | - public IpAddress ovsdbIp() { | 92 | + public NetworkAddress localMgmtIp() { |
69 | - return this.ovsdbIp; | 93 | + return this.localMgmtIp; |
70 | } | 94 | } |
71 | 95 | ||
72 | /** | 96 | /** |
73 | - * Returns the OVSDB server port number. | 97 | + * Returns the data plane network address. |
98 | + * | ||
99 | + * @return network address | ||
100 | + */ | ||
101 | + public NetworkAddress dpIp() { | ||
102 | + return this.dpIp; | ||
103 | + } | ||
104 | + | ||
105 | + /** | ||
106 | + * Returns the port number used for OVSDB connection. | ||
74 | * | 107 | * |
75 | * @return port number | 108 | * @return port number |
76 | */ | 109 | */ |
... | @@ -79,12 +112,12 @@ public final class CordVtnNode { | ... | @@ -79,12 +112,12 @@ public final class CordVtnNode { |
79 | } | 112 | } |
80 | 113 | ||
81 | /** | 114 | /** |
82 | - * Returns the hostname. | 115 | + * Returns the SSH access information. |
83 | * | 116 | * |
84 | - * @return hostname | 117 | + * @return ssh access information |
85 | */ | 118 | */ |
86 | - public String hostname() { | 119 | + public SshAccessInfo sshInfo() { |
87 | - return this.hostname; | 120 | + return this.sshInfo; |
88 | } | 121 | } |
89 | 122 | ||
90 | /** | 123 | /** |
... | @@ -102,25 +135,16 @@ public final class CordVtnNode { | ... | @@ -102,25 +135,16 @@ public final class CordVtnNode { |
102 | * @return device id | 135 | * @return device id |
103 | */ | 136 | */ |
104 | public DeviceId ovsdbId() { | 137 | public DeviceId ovsdbId() { |
105 | - return DeviceId.deviceId("ovsdb:" + this.ovsdbIp.toString()); | 138 | + return DeviceId.deviceId("ovsdb:" + this.hostMgmtIp.ip().toString()); |
106 | - } | ||
107 | - | ||
108 | - /** | ||
109 | - * Returns physical port name. | ||
110 | - * | ||
111 | - * @return physical port name | ||
112 | - */ | ||
113 | - public String phyPortName() { | ||
114 | - return this.phyPortName; | ||
115 | } | 139 | } |
116 | 140 | ||
117 | /** | 141 | /** |
118 | - * Returns local IP address. | 142 | + * Returns data plane interface name. |
119 | * | 143 | * |
120 | - * @return ip address | 144 | + * @return data plane interface name |
121 | */ | 145 | */ |
122 | - public IpAddress localIp() { | 146 | + public String dpIntf() { |
123 | - return this.localIp; | 147 | + return this.dpIntf; |
124 | } | 148 | } |
125 | 149 | ||
126 | @Override | 150 | @Override |
... | @@ -129,6 +153,8 @@ public final class CordVtnNode { | ... | @@ -129,6 +153,8 @@ public final class CordVtnNode { |
129 | return true; | 153 | return true; |
130 | } | 154 | } |
131 | 155 | ||
156 | + // hostname here is a network hostname and it is intended to be | ||
157 | + // unique throughout the service. | ||
132 | if (obj instanceof CordVtnNode) { | 158 | if (obj instanceof CordVtnNode) { |
133 | CordVtnNode that = (CordVtnNode) obj; | 159 | CordVtnNode that = (CordVtnNode) obj; |
134 | if (Objects.equals(hostname, that.hostname)) { | 160 | if (Objects.equals(hostname, that.hostname)) { |
... | @@ -146,12 +172,14 @@ public final class CordVtnNode { | ... | @@ -146,12 +172,14 @@ public final class CordVtnNode { |
146 | @Override | 172 | @Override |
147 | public String toString() { | 173 | public String toString() { |
148 | return MoreObjects.toStringHelper(getClass()) | 174 | return MoreObjects.toStringHelper(getClass()) |
149 | - .add("host", hostname) | 175 | + .add("hostname", hostname) |
150 | - .add("ip", ovsdbIp) | 176 | + .add("hostMgmtIp", hostMgmtIp) |
177 | + .add("localMgmtIp", localMgmtIp) | ||
178 | + .add("dpIp", dpIp) | ||
151 | .add("port", ovsdbPort) | 179 | .add("port", ovsdbPort) |
180 | + .add("sshInfo", sshInfo) | ||
152 | .add("bridgeId", bridgeId) | 181 | .add("bridgeId", bridgeId) |
153 | - .add("phyPortName", phyPortName) | 182 | + .add("dpIntf", dpIntf) |
154 | - .add("localIp", localIp) | ||
155 | .toString(); | 183 | .toString(); |
156 | } | 184 | } |
157 | } | 185 | } | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -96,6 +96,7 @@ public class CordVtnRuleInstaller { | ... | @@ -96,6 +96,7 @@ public class CordVtnRuleInstaller { |
96 | 96 | ||
97 | protected final Logger log = getLogger(getClass()); | 97 | protected final Logger log = getLogger(getClass()); |
98 | 98 | ||
99 | + private static final String PORT_NAME = "portName"; | ||
99 | private static final int TABLE_FIRST = 0; | 100 | private static final int TABLE_FIRST = 0; |
100 | private static final int TABLE_IN_PORT = 1; | 101 | private static final int TABLE_IN_PORT = 1; |
101 | private static final int TABLE_ACCESS_TYPE = 2; | 102 | private static final int TABLE_ACCESS_TYPE = 2; |
... | @@ -150,18 +151,18 @@ public class CordVtnRuleInstaller { | ... | @@ -150,18 +151,18 @@ public class CordVtnRuleInstaller { |
150 | * Installs table miss rule to a give device. | 151 | * Installs table miss rule to a give device. |
151 | * | 152 | * |
152 | * @param deviceId device id to install the rules | 153 | * @param deviceId device id to install the rules |
153 | - * @param phyPortName physical port name | 154 | + * @param dpIntf data plane interface name |
154 | - * @param localIp local data plane ip address | 155 | + * @param dpIp data plane ip address |
155 | */ | 156 | */ |
156 | - public void init(DeviceId deviceId, String phyPortName, IpAddress localIp) { | 157 | + public void init(DeviceId deviceId, String dpIntf, IpAddress dpIp) { |
157 | // default is drop packets which can be accomplished without | 158 | // default is drop packets which can be accomplished without |
158 | // a table miss entry for all table. | 159 | // a table miss entry for all table. |
159 | PortNumber tunnelPort = getTunnelPort(deviceId); | 160 | PortNumber tunnelPort = getTunnelPort(deviceId); |
160 | - PortNumber phyPort = getPhyPort(deviceId, phyPortName); | 161 | + PortNumber dpPort = getDpPort(deviceId, dpIntf); |
161 | 162 | ||
162 | - processFirstTable(deviceId, phyPort, localIp); | 163 | + processFirstTable(deviceId, dpPort, dpIp); |
163 | - processInPortTable(deviceId, tunnelPort, phyPort); | 164 | + processInPortTable(deviceId, tunnelPort, dpPort); |
164 | - processAccessTypeTable(deviceId, phyPort); | 165 | + processAccessTypeTable(deviceId, dpPort); |
165 | } | 166 | } |
166 | 167 | ||
167 | /** | 168 | /** |
... | @@ -510,21 +511,21 @@ public class CordVtnRuleInstaller { | ... | @@ -510,21 +511,21 @@ public class CordVtnRuleInstaller { |
510 | 511 | ||
511 | /** | 512 | /** |
512 | * Populates default rules on the first table. | 513 | * Populates default rules on the first table. |
513 | - * The rules are for shuttling vxlan-encapped packets and supporting physical | 514 | + * It includes the rules for shuttling vxlan-encapped packets between ovs and |
514 | - * network connectivity. | 515 | + * linux stack,and external network connectivity. |
515 | * | 516 | * |
516 | * @param deviceId device id | 517 | * @param deviceId device id |
517 | - * @param phyPort physical port number | 518 | + * @param dpPort data plane interface port number |
518 | - * @param localIp local data plane ip address | 519 | + * @param dpIp data plane ip address |
519 | */ | 520 | */ |
520 | - private void processFirstTable(DeviceId deviceId, PortNumber phyPort, IpAddress localIp) { | 521 | + private void processFirstTable(DeviceId deviceId, PortNumber dpPort, IpAddress dpIp) { |
521 | // take vxlan packet out onto the physical port | 522 | // take vxlan packet out onto the physical port |
522 | TrafficSelector selector = DefaultTrafficSelector.builder() | 523 | TrafficSelector selector = DefaultTrafficSelector.builder() |
523 | .matchInPort(PortNumber.LOCAL) | 524 | .matchInPort(PortNumber.LOCAL) |
524 | .build(); | 525 | .build(); |
525 | 526 | ||
526 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() | 527 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
527 | - .setOutput(phyPort) | 528 | + .setOutput(dpPort) |
528 | .build(); | 529 | .build(); |
529 | 530 | ||
530 | FlowRule flowRule = DefaultFlowRule.builder() | 531 | FlowRule flowRule = DefaultFlowRule.builder() |
... | @@ -541,7 +542,7 @@ public class CordVtnRuleInstaller { | ... | @@ -541,7 +542,7 @@ public class CordVtnRuleInstaller { |
541 | 542 | ||
542 | // take a vxlan encap'd packet through the Linux stack | 543 | // take a vxlan encap'd packet through the Linux stack |
543 | selector = DefaultTrafficSelector.builder() | 544 | selector = DefaultTrafficSelector.builder() |
544 | - .matchInPort(phyPort) | 545 | + .matchInPort(dpPort) |
545 | .matchEthType(Ethernet.TYPE_IPV4) | 546 | .matchEthType(Ethernet.TYPE_IPV4) |
546 | .matchIPProtocol(IPv4.PROTOCOL_UDP) | 547 | .matchIPProtocol(IPv4.PROTOCOL_UDP) |
547 | .matchUdpDst(TpPort.tpPort(VXLAN_UDP_PORT)) | 548 | .matchUdpDst(TpPort.tpPort(VXLAN_UDP_PORT)) |
... | @@ -563,11 +564,11 @@ public class CordVtnRuleInstaller { | ... | @@ -563,11 +564,11 @@ public class CordVtnRuleInstaller { |
563 | 564 | ||
564 | processFlowRule(true, flowRule); | 565 | processFlowRule(true, flowRule); |
565 | 566 | ||
566 | - // take a packet to the local ip through Linux stack | 567 | + // take a packet to the data plane ip through Linux stack |
567 | selector = DefaultTrafficSelector.builder() | 568 | selector = DefaultTrafficSelector.builder() |
568 | - .matchInPort(phyPort) | 569 | + .matchInPort(dpPort) |
569 | .matchEthType(Ethernet.TYPE_IPV4) | 570 | .matchEthType(Ethernet.TYPE_IPV4) |
570 | - .matchIPDst(localIp.toIpPrefix()) | 571 | + .matchIPDst(dpIp.toIpPrefix()) |
571 | .build(); | 572 | .build(); |
572 | 573 | ||
573 | treatment = DefaultTrafficTreatment.builder() | 574 | treatment = DefaultTrafficTreatment.builder() |
... | @@ -588,7 +589,7 @@ public class CordVtnRuleInstaller { | ... | @@ -588,7 +589,7 @@ public class CordVtnRuleInstaller { |
588 | 589 | ||
589 | // take an arp packet from physical through Linux stack | 590 | // take an arp packet from physical through Linux stack |
590 | selector = DefaultTrafficSelector.builder() | 591 | selector = DefaultTrafficSelector.builder() |
591 | - .matchInPort(phyPort) | 592 | + .matchInPort(dpPort) |
592 | .matchEthType(Ethernet.TYPE_ARP) | 593 | .matchEthType(Ethernet.TYPE_ARP) |
593 | .build(); | 594 | .build(); |
594 | 595 | ||
... | @@ -630,17 +631,17 @@ public class CordVtnRuleInstaller { | ... | @@ -630,17 +631,17 @@ public class CordVtnRuleInstaller { |
630 | } | 631 | } |
631 | 632 | ||
632 | /** | 633 | /** |
633 | - * Forward table miss packets in ACCESS_TYPE table to physical port. | 634 | + * Forward table miss packets in ACCESS_TYPE table to data plane port. |
634 | * | 635 | * |
635 | * @param deviceId device id | 636 | * @param deviceId device id |
636 | - * @param phyPort physical port number | 637 | + * @param dpPort data plane interface port number |
637 | */ | 638 | */ |
638 | - private void processAccessTypeTable(DeviceId deviceId, PortNumber phyPort) { | 639 | + private void processAccessTypeTable(DeviceId deviceId, PortNumber dpPort) { |
639 | TrafficSelector selector = DefaultTrafficSelector.builder() | 640 | TrafficSelector selector = DefaultTrafficSelector.builder() |
640 | .build(); | 641 | .build(); |
641 | 642 | ||
642 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() | 643 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
643 | - .setOutput(phyPort) | 644 | + .setOutput(dpPort) |
644 | .build(); | 645 | .build(); |
645 | 646 | ||
646 | FlowRule flowRule = DefaultFlowRule.builder() | 647 | FlowRule flowRule = DefaultFlowRule.builder() |
... | @@ -659,13 +660,13 @@ public class CordVtnRuleInstaller { | ... | @@ -659,13 +660,13 @@ public class CordVtnRuleInstaller { |
659 | /** | 660 | /** |
660 | * Populates default rules for IN_PORT table. | 661 | * Populates default rules for IN_PORT table. |
661 | * All packets from tunnel port are forwarded to TUNNEL_ID table and all packets | 662 | * All packets from tunnel port are forwarded to TUNNEL_ID table and all packets |
662 | - * from physical port to ACCESS_TYPE table. | 663 | + * from data plane interface port to ACCESS_TYPE table. |
663 | * | 664 | * |
664 | * @param deviceId device id to install the rules | 665 | * @param deviceId device id to install the rules |
665 | * @param tunnelPort tunnel port number | 666 | * @param tunnelPort tunnel port number |
666 | - * @param phyPort physical port number | 667 | + * @param dpPort data plane interface port number |
667 | */ | 668 | */ |
668 | - private void processInPortTable(DeviceId deviceId, PortNumber tunnelPort, PortNumber phyPort) { | 669 | + private void processInPortTable(DeviceId deviceId, PortNumber tunnelPort, PortNumber dpPort) { |
669 | checkNotNull(tunnelPort); | 670 | checkNotNull(tunnelPort); |
670 | 671 | ||
671 | TrafficSelector selector = DefaultTrafficSelector.builder() | 672 | TrafficSelector selector = DefaultTrafficSelector.builder() |
... | @@ -689,7 +690,7 @@ public class CordVtnRuleInstaller { | ... | @@ -689,7 +690,7 @@ public class CordVtnRuleInstaller { |
689 | processFlowRule(true, flowRule); | 690 | processFlowRule(true, flowRule); |
690 | 691 | ||
691 | selector = DefaultTrafficSelector.builder() | 692 | selector = DefaultTrafficSelector.builder() |
692 | - .matchInPort(phyPort) | 693 | + .matchInPort(dpPort) |
693 | .build(); | 694 | .build(); |
694 | 695 | ||
695 | treatment = DefaultTrafficTreatment.builder() | 696 | treatment = DefaultTrafficTreatment.builder() |
... | @@ -1027,22 +1028,22 @@ public class CordVtnRuleInstaller { | ... | @@ -1027,22 +1028,22 @@ public class CordVtnRuleInstaller { |
1027 | */ | 1028 | */ |
1028 | private PortNumber getTunnelPort(DeviceId deviceId) { | 1029 | private PortNumber getTunnelPort(DeviceId deviceId) { |
1029 | Port port = deviceService.getPorts(deviceId).stream() | 1030 | Port port = deviceService.getPorts(deviceId).stream() |
1030 | - .filter(p -> p.annotations().value("portName").contains(tunnelType)) | 1031 | + .filter(p -> p.annotations().value(PORT_NAME).contains(tunnelType)) |
1031 | .findFirst().orElse(null); | 1032 | .findFirst().orElse(null); |
1032 | 1033 | ||
1033 | return port == null ? null : port.number(); | 1034 | return port == null ? null : port.number(); |
1034 | } | 1035 | } |
1035 | 1036 | ||
1036 | /** | 1037 | /** |
1037 | - * Returns physical port name of a given device. | 1038 | + * Returns data plane interface port name of a given device. |
1038 | * | 1039 | * |
1039 | * @param deviceId device id | 1040 | * @param deviceId device id |
1040 | - * @param phyPortName physical port name | 1041 | + * @param dpIntf data plane interface port name |
1041 | - * @return physical port number, or null if no physical port exists | 1042 | + * @return data plane interface port number, or null if no such port exists |
1042 | */ | 1043 | */ |
1043 | - private PortNumber getPhyPort(DeviceId deviceId, String phyPortName) { | 1044 | + private PortNumber getDpPort(DeviceId deviceId, String dpIntf) { |
1044 | Port port = deviceService.getPorts(deviceId).stream() | 1045 | Port port = deviceService.getPorts(deviceId).stream() |
1045 | - .filter(p -> p.annotations().value("portName").contains(phyPortName) && | 1046 | + .filter(p -> p.annotations().value(PORT_NAME).contains(dpIntf) && |
1046 | p.isEnabled()) | 1047 | p.isEnabled()) |
1047 | .findFirst().orElse(null); | 1048 | .findFirst().orElse(null); |
1048 | 1049 | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (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 | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.cordvtn; | ||
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | +import org.onlab.packet.IpAddress; | ||
20 | +import org.onlab.packet.IpPrefix; | ||
21 | + | ||
22 | +import java.util.Objects; | ||
23 | + | ||
24 | +import static com.google.common.base.Preconditions.checkArgument; | ||
25 | + | ||
26 | +/** | ||
27 | + * Representation of a network address, which consists of IP address and prefix. | ||
28 | + */ | ||
29 | +public final class NetworkAddress { | ||
30 | + private final IpAddress ip; | ||
31 | + private final IpPrefix prefix; | ||
32 | + | ||
33 | + /** | ||
34 | + * Constructor for a given IP address and prefix. | ||
35 | + * | ||
36 | + * @param ip ip address | ||
37 | + * @param prefix ip prefix | ||
38 | + */ | ||
39 | + public NetworkAddress(IpAddress ip, IpPrefix prefix) { | ||
40 | + this.ip = ip; | ||
41 | + this.prefix = prefix; | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * Converts a CIDR notation string into a network address. | ||
46 | + * | ||
47 | + * @param cidr cidr | ||
48 | + * @return network address | ||
49 | + * @throws IllegalArgumentException if the cidr is not valid | ||
50 | + */ | ||
51 | + public static NetworkAddress valueOf(String cidr) { | ||
52 | + checkArgument(cidr.contains("/")); | ||
53 | + | ||
54 | + IpAddress ipAddress = IpAddress.valueOf(cidr.split("/")[0]); | ||
55 | + IpPrefix ipPrefix = IpPrefix.valueOf(cidr); | ||
56 | + | ||
57 | + return new NetworkAddress(ipAddress, ipPrefix); | ||
58 | + } | ||
59 | + | ||
60 | + /** | ||
61 | + * Returns the IP address value of the network address. | ||
62 | + * | ||
63 | + * @return ip address | ||
64 | + */ | ||
65 | + public IpAddress ip() { | ||
66 | + return this.ip; | ||
67 | + } | ||
68 | + | ||
69 | + /** | ||
70 | + * Returns the IP prefix value of the network address. | ||
71 | + * | ||
72 | + * @return ip prefix | ||
73 | + */ | ||
74 | + public IpPrefix prefix() { | ||
75 | + return this.prefix; | ||
76 | + } | ||
77 | + | ||
78 | + /** | ||
79 | + * Converts a network address to a CIDR notation. | ||
80 | + * | ||
81 | + * @return cidr notation string | ||
82 | + */ | ||
83 | + public String cidr() { | ||
84 | + return ip.toString() + "/" + prefix.prefixLength(); | ||
85 | + } | ||
86 | + | ||
87 | + @Override | ||
88 | + public boolean equals(Object obj) { | ||
89 | + if (this == obj) { | ||
90 | + return true; | ||
91 | + } | ||
92 | + | ||
93 | + if (obj instanceof NetworkAddress) { | ||
94 | + NetworkAddress that = (NetworkAddress) obj; | ||
95 | + if (Objects.equals(ip, that.ip) && Objects.equals(prefix, that.prefix)) { | ||
96 | + return true; | ||
97 | + } | ||
98 | + } | ||
99 | + return false; | ||
100 | + } | ||
101 | + | ||
102 | + @Override | ||
103 | + public int hashCode() { | ||
104 | + return Objects.hash(ip, prefix); | ||
105 | + } | ||
106 | + | ||
107 | + @Override | ||
108 | + public String toString() { | ||
109 | + return MoreObjects.toStringHelper(getClass()) | ||
110 | + .add("IpAddress", ip) | ||
111 | + .add("IpPrefix", prefix) | ||
112 | + .toString(); | ||
113 | + } | ||
114 | +} |
... | @@ -22,7 +22,7 @@ import com.jcraft.jsch.ChannelExec; | ... | @@ -22,7 +22,7 @@ import com.jcraft.jsch.ChannelExec; |
22 | import com.jcraft.jsch.JSch; | 22 | import com.jcraft.jsch.JSch; |
23 | import com.jcraft.jsch.JSchException; | 23 | import com.jcraft.jsch.JSchException; |
24 | import com.jcraft.jsch.Session; | 24 | import com.jcraft.jsch.Session; |
25 | -import org.onlab.packet.IpPrefix; | 25 | +import org.onlab.packet.IpAddress; |
26 | import org.slf4j.Logger; | 26 | import org.slf4j.Logger; |
27 | 27 | ||
28 | import java.io.IOException; | 28 | import java.io.IOException; |
... | @@ -48,8 +48,10 @@ public final class RemoteIpCommandUtil { | ... | @@ -48,8 +48,10 @@ public final class RemoteIpCommandUtil { |
48 | private static final String DEFAULT_STRICT_HOST_CHECKING = "no"; | 48 | private static final String DEFAULT_STRICT_HOST_CHECKING = "no"; |
49 | private static final int DEFAULT_SESSION_TIMEOUT = 60000; // milliseconds | 49 | private static final int DEFAULT_SESSION_TIMEOUT = 60000; // milliseconds |
50 | 50 | ||
51 | - private static final String IP_PATTERN = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.)" + | 51 | + private static final String IP_PATTERN = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + |
52 | - "{3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\\/([0-9]|[1-2][0-9]|3[0-2]))$"; | 52 | + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + |
53 | + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + | ||
54 | + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"; | ||
53 | 55 | ||
54 | private static final String IP_ADDR_SHOW = "sudo ip addr show %s"; | 56 | private static final String IP_ADDR_SHOW = "sudo ip addr show %s"; |
55 | private static final String IP_ADDR_FLUSH = "sudo ip addr flush %s"; | 57 | private static final String IP_ADDR_FLUSH = "sudo ip addr flush %s"; |
... | @@ -68,18 +70,18 @@ public final class RemoteIpCommandUtil { | ... | @@ -68,18 +70,18 @@ public final class RemoteIpCommandUtil { |
68 | * Adds a given IP address to a given device. | 70 | * Adds a given IP address to a given device. |
69 | * | 71 | * |
70 | * @param session ssh connection | 72 | * @param session ssh connection |
71 | - * @param ip ip address | 73 | + * @param ip network address |
72 | * @param device device name to assign the ip address | 74 | * @param device device name to assign the ip address |
73 | * @return true if the command succeeds, or false | 75 | * @return true if the command succeeds, or false |
74 | */ | 76 | */ |
75 | - public static boolean addIp(Session session, IpPrefix ip, String device) { | 77 | + public static boolean addIp(Session session, NetworkAddress ip, String device) { |
76 | if (session == null || !session.isConnected()) { | 78 | if (session == null || !session.isConnected()) { |
77 | return false; | 79 | return false; |
78 | } | 80 | } |
79 | 81 | ||
80 | - executeCommand(session, String.format(IP_ADDR_ADD, ip, device)); | 82 | + executeCommand(session, String.format(IP_ADDR_ADD, ip.cidr(), device)); |
81 | - Set<IpPrefix> result = getCurrentIps(session, device); | 83 | + Set<IpAddress> result = getCurrentIps(session, device); |
82 | - return result.contains(ip); | 84 | + return result.contains(ip.ip()); |
83 | } | 85 | } |
84 | 86 | ||
85 | /** | 87 | /** |
... | @@ -90,13 +92,13 @@ public final class RemoteIpCommandUtil { | ... | @@ -90,13 +92,13 @@ public final class RemoteIpCommandUtil { |
90 | * @param device device name | 92 | * @param device device name |
91 | * @return true if the command succeeds, or false | 93 | * @return true if the command succeeds, or false |
92 | */ | 94 | */ |
93 | - public static boolean deleteIp(Session session, IpPrefix ip, String device) { | 95 | + public static boolean deleteIp(Session session, IpAddress ip, String device) { |
94 | if (session == null || !session.isConnected()) { | 96 | if (session == null || !session.isConnected()) { |
95 | return false; | 97 | return false; |
96 | } | 98 | } |
97 | 99 | ||
98 | executeCommand(session, String.format(IP_ADDR_DELETE, ip, device)); | 100 | executeCommand(session, String.format(IP_ADDR_DELETE, ip, device)); |
99 | - Set<IpPrefix> result = getCurrentIps(session, device); | 101 | + Set<IpAddress> result = getCurrentIps(session, device); |
100 | return !result.contains(ip); | 102 | return !result.contains(ip); |
101 | } | 103 | } |
102 | 104 | ||
... | @@ -123,16 +125,16 @@ public final class RemoteIpCommandUtil { | ... | @@ -123,16 +125,16 @@ public final class RemoteIpCommandUtil { |
123 | * @param device device name | 125 | * @param device device name |
124 | * @return set of IP prefix or empty set | 126 | * @return set of IP prefix or empty set |
125 | */ | 127 | */ |
126 | - public static Set<IpPrefix> getCurrentIps(Session session, String device) { | 128 | + public static Set<IpAddress> getCurrentIps(Session session, String device) { |
127 | if (session == null || !session.isConnected()) { | 129 | if (session == null || !session.isConnected()) { |
128 | return Sets.newHashSet(); | 130 | return Sets.newHashSet(); |
129 | } | 131 | } |
130 | 132 | ||
131 | String output = executeCommand(session, String.format(IP_ADDR_SHOW, device)); | 133 | String output = executeCommand(session, String.format(IP_ADDR_SHOW, device)); |
132 | - Set<IpPrefix> result = Pattern.compile(" ") | 134 | + Set<IpAddress> result = Pattern.compile(" |/") |
133 | .splitAsStream(output) | 135 | .splitAsStream(output) |
134 | .filter(s -> s.matches(IP_PATTERN)) | 136 | .filter(s -> s.matches(IP_PATTERN)) |
135 | - .map(IpPrefix::valueOf) | 137 | + .map(IpAddress::valueOf) |
136 | .collect(Collectors.toSet()); | 138 | .collect(Collectors.toSet()); |
137 | 139 | ||
138 | return result; | 140 | return result; | ... | ... |
apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/CordVtnNodeAddCommand.java
deleted
100644 → 0
1 | -/* | ||
2 | - * Copyright 2015 Open Networking Laboratory | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (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 | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | - | ||
17 | -package org.onosproject.cordvtn.cli; | ||
18 | - | ||
19 | -import org.apache.karaf.shell.commands.Argument; | ||
20 | -import org.apache.karaf.shell.commands.Command; | ||
21 | -import org.onlab.packet.IpAddress; | ||
22 | -import org.onlab.packet.TpPort; | ||
23 | -import org.onosproject.cli.AbstractShellCommand; | ||
24 | -import org.onosproject.cordvtn.CordVtnNodeManager; | ||
25 | -import org.onosproject.cordvtn.CordVtnNode; | ||
26 | -import org.onosproject.net.DeviceId; | ||
27 | - | ||
28 | -import static com.google.common.base.Preconditions.checkArgument; | ||
29 | - | ||
30 | -/** | ||
31 | - * Adds a new node to the service. | ||
32 | - */ | ||
33 | -@Command(scope = "onos", name = "cordvtn-node-add", | ||
34 | - description = "Adds a new node to CORD VTN service") | ||
35 | -public class CordVtnNodeAddCommand extends AbstractShellCommand { | ||
36 | - | ||
37 | - @Argument(index = 0, name = "hostname", description = "Hostname", | ||
38 | - required = true, multiValued = false) | ||
39 | - private String hostname = null; | ||
40 | - | ||
41 | - @Argument(index = 1, name = "ovsdb", | ||
42 | - description = "OVSDB server listening address (ip:port)", | ||
43 | - required = true, multiValued = false) | ||
44 | - private String ovsdb = null; | ||
45 | - | ||
46 | - @Argument(index = 2, name = "bridgeId", | ||
47 | - description = "Device ID of integration bridge", | ||
48 | - required = true, multiValued = false) | ||
49 | - private String bridgeId = null; | ||
50 | - | ||
51 | - @Argument(index = 3, name = "phyPortName", | ||
52 | - description = "Physical port name", | ||
53 | - required = true, multiValued = false) | ||
54 | - private String phyPortName = null; | ||
55 | - | ||
56 | - @Argument(index = 4, name = "localIp", | ||
57 | - description = "Local data plane IP address", | ||
58 | - required = true, multiValued = false) | ||
59 | - private String localIp = null; | ||
60 | - | ||
61 | - @Override | ||
62 | - protected void execute() { | ||
63 | - checkArgument(ovsdb.contains(":"), "OVSDB address should be ip:port format"); | ||
64 | - checkArgument(bridgeId.startsWith("of:"), "bridgeId should be of:dpid format"); | ||
65 | - | ||
66 | - CordVtnNodeManager nodeManager = AbstractShellCommand.get(CordVtnNodeManager.class); | ||
67 | - String[] ipPort = ovsdb.split(":"); | ||
68 | - CordVtnNode node = new CordVtnNode(hostname, | ||
69 | - IpAddress.valueOf(ipPort[0]), | ||
70 | - TpPort.tpPort(Integer.parseInt(ipPort[1])), | ||
71 | - DeviceId.deviceId(bridgeId), | ||
72 | - phyPortName, | ||
73 | - IpAddress.valueOf(localIp)); | ||
74 | - nodeManager.addNode(node); | ||
75 | - } | ||
76 | -} |
... | @@ -34,6 +34,9 @@ import java.util.List; | ... | @@ -34,6 +34,9 @@ import java.util.List; |
34 | description = "Lists all nodes registered in CORD VTN service") | 34 | description = "Lists all nodes registered in CORD VTN service") |
35 | public class CordVtnNodeListCommand extends AbstractShellCommand { | 35 | public class CordVtnNodeListCommand extends AbstractShellCommand { |
36 | 36 | ||
37 | + private static final String COMPLETE = "COMPLETE"; | ||
38 | + private static final String INCOMPLETE = "INCOMPLETE"; | ||
39 | + | ||
37 | @Override | 40 | @Override |
38 | protected void execute() { | 41 | protected void execute() { |
39 | CordVtnNodeManager nodeManager = AbstractShellCommand.get(CordVtnNodeManager.class); | 42 | CordVtnNodeManager nodeManager = AbstractShellCommand.get(CordVtnNodeManager.class); |
... | @@ -44,12 +47,12 @@ public class CordVtnNodeListCommand extends AbstractShellCommand { | ... | @@ -44,12 +47,12 @@ public class CordVtnNodeListCommand extends AbstractShellCommand { |
44 | print("%s", json(nodeManager, nodes)); | 47 | print("%s", json(nodeManager, nodes)); |
45 | } else { | 48 | } else { |
46 | for (CordVtnNode node : nodes) { | 49 | for (CordVtnNode node : nodes) { |
47 | - print("hostname=%s, ovsdb=%s, br-int=%s, phyPort=%s, localIp=%s, init=%s", | 50 | + print("hostname=%s, hostMgmtIp=%s, dpIp=%s, br-int=%s, dpIntf=%s, init=%s", |
48 | node.hostname(), | 51 | node.hostname(), |
49 | - node.ovsdbIp().toString() + ":" + node.ovsdbPort().toString(), | 52 | + node.hostMgmtIp().cidr(), |
53 | + node.dpIp().cidr(), | ||
50 | node.intBrId().toString(), | 54 | node.intBrId().toString(), |
51 | - node.phyPortName(), | 55 | + node.dpIntf(), |
52 | - node.localIp().toString(), | ||
53 | getState(nodeManager, node)); | 56 | getState(nodeManager, node)); |
54 | } | 57 | } |
55 | print("Total %s nodes", nodeManager.getNodeCount()); | 58 | print("Total %s nodes", nodeManager.getNodeCount()); |
... | @@ -60,19 +63,18 @@ public class CordVtnNodeListCommand extends AbstractShellCommand { | ... | @@ -60,19 +63,18 @@ public class CordVtnNodeListCommand extends AbstractShellCommand { |
60 | ObjectMapper mapper = new ObjectMapper(); | 63 | ObjectMapper mapper = new ObjectMapper(); |
61 | ArrayNode result = mapper.createArrayNode(); | 64 | ArrayNode result = mapper.createArrayNode(); |
62 | for (CordVtnNode node : nodes) { | 65 | for (CordVtnNode node : nodes) { |
63 | - String ipPort = node.ovsdbIp().toString() + ":" + node.ovsdbPort().toString(); | ||
64 | result.add(mapper.createObjectNode() | 66 | result.add(mapper.createObjectNode() |
65 | .put("hostname", node.hostname()) | 67 | .put("hostname", node.hostname()) |
66 | - .put("ovsdb", ipPort) | 68 | + .put("hostManagementIp", node.hostMgmtIp().cidr()) |
67 | - .put("brInt", node.intBrId().toString()) | 69 | + .put("dataPlaneIp", node.dpIp().cidr()) |
68 | - .put("phyPort", node.phyPortName()) | 70 | + .put("bridgeId", node.intBrId().toString()) |
69 | - .put("localIp", node.localIp().toString()) | 71 | + .put("dataPlaneInterface", node.dpIntf()) |
70 | .put("init", getState(nodeManager, node))); | 72 | .put("init", getState(nodeManager, node))); |
71 | } | 73 | } |
72 | return result; | 74 | return result; |
73 | } | 75 | } |
74 | 76 | ||
75 | private String getState(CordVtnNodeManager nodeManager, CordVtnNode node) { | 77 | private String getState(CordVtnNodeManager nodeManager, CordVtnNode node) { |
76 | - return nodeManager.getNodeInitState(node) ? "COMPLETE" : "INCOMPLETE"; | 78 | + return nodeManager.isNodeInitComplete(node) ? COMPLETE : INCOMPLETE; |
77 | } | 79 | } |
78 | } | 80 | } | ... | ... |
... | @@ -20,9 +20,6 @@ | ... | @@ -20,9 +20,6 @@ |
20 | <action class="org.onosproject.cordvtn.cli.CordVtnNodeListCommand"/> | 20 | <action class="org.onosproject.cordvtn.cli.CordVtnNodeListCommand"/> |
21 | </command> | 21 | </command> |
22 | <command> | 22 | <command> |
23 | - <action class="org.onosproject.cordvtn.cli.CordVtnNodeAddCommand"/> | ||
24 | - </command> | ||
25 | - <command> | ||
26 | <action class="org.onosproject.cordvtn.cli.CordVtnNodeDeleteCommand"/> | 23 | <action class="org.onosproject.cordvtn.cli.CordVtnNodeDeleteCommand"/> |
27 | </command> | 24 | </command> |
28 | <command> | 25 | <command> | ... | ... |
-
Please register or login to post a comment