blob: f5f93dc14496ab7dbf7adacc8f02b3e59d1a51fb [file] [log] [blame]
sanghoshin94872a12015-10-16 18:04:34 +09001/*
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
17package org.onosproject.openstackswitching;
18
19import org.onlab.packet.Ethernet;
sanghoshin94872a12015-10-16 18:04:34 +090020import org.onlab.packet.Ip4Address;
sanghoshin94872a12015-10-16 18:04:34 +090021import org.onosproject.core.ApplicationId;
sanghoshinf25d2e02015-11-11 23:07:17 +090022import org.onosproject.net.Device;
sanghoshin94872a12015-10-16 18:04:34 +090023import org.onosproject.net.DeviceId;
24import org.onosproject.net.Port;
25import org.onosproject.net.PortNumber;
sanghoshinf25d2e02015-11-11 23:07:17 +090026import org.onosproject.net.behaviour.ExtensionTreatmentResolver;
27import org.onosproject.net.device.DeviceService;
28import org.onosproject.net.driver.DefaultDriverData;
29import org.onosproject.net.driver.DefaultDriverHandler;
30import org.onosproject.net.driver.Driver;
31import org.onosproject.net.driver.DriverHandler;
32import org.onosproject.net.driver.DriverService;
sanghoshin94872a12015-10-16 18:04:34 +090033import org.onosproject.net.flow.DefaultTrafficSelector;
34import org.onosproject.net.flow.DefaultTrafficTreatment;
35import org.onosproject.net.flow.TrafficSelector;
36import org.onosproject.net.flow.TrafficTreatment;
sanghoshinf25d2e02015-11-11 23:07:17 +090037import org.onosproject.net.flow.instructions.ExtensionTreatment;
38import org.onosproject.net.flow.instructions.ExtensionPropertyException;
39import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
sanghoshin94872a12015-10-16 18:04:34 +090040import org.onosproject.net.flowobjective.DefaultForwardingObjective;
41import org.onosproject.net.flowobjective.FlowObjectiveService;
42import org.onosproject.net.flowobjective.ForwardingObjective;
43import org.slf4j.Logger;
44import org.slf4j.LoggerFactory;
45
sanghoshinf25d2e02015-11-11 23:07:17 +090046import java.util.Collection;
Daniel Park5df65182016-01-09 00:12:03 +090047import java.util.Map;
sanghoshinf25d2e02015-11-11 23:07:17 +090048
sanghoshin94872a12015-10-16 18:04:34 +090049/**
sanghoshin46297d22015-11-03 17:51:24 +090050 * Populates switching flow rules.
sanghoshin94872a12015-10-16 18:04:34 +090051 */
52public class OpenstackSwitchingRulePopulator {
53
54 private static Logger log = LoggerFactory
55 .getLogger(OpenstackSwitchingRulePopulator.class);
daniel2a2bd7b2015-12-02 13:53:58 +090056 private static final int SWITCHING_RULE_PRIORITY = 30000;
57 private static final int EAST_WEST_ROUTING_RULE_PRIORITY = 29000;
58 private static final int TUNNELTAG_RULE_PRIORITY = 30000;
sanghoshin94872a12015-10-16 18:04:34 +090059
60 private FlowObjectiveService flowObjectiveService;
sanghoshinf25d2e02015-11-11 23:07:17 +090061 private DriverService driverService;
62 private DeviceService deviceService;
63 private OpenstackRestHandler restHandler;
sanghoshin94872a12015-10-16 18:04:34 +090064 private ApplicationId appId;
65
sanghoshinf25d2e02015-11-11 23:07:17 +090066 private Collection<OpenstackNetwork> openstackNetworkList;
67 private Collection<OpenstackPort> openstackPortList;
68
sanghoshin94872a12015-10-16 18:04:34 +090069 /**
Ray Milkey87b16b02015-10-30 11:50:00 -070070 * Creates OpenstackSwitchingRulPopulator.
71 *
72 * @param appId application id
sanghoshin94872a12015-10-16 18:04:34 +090073 * @param flowObjectiveService FlowObjectiveService reference
sanghoshinf25d2e02015-11-11 23:07:17 +090074 * @param deviceService DeviceService reference
75 * @param driverService DriverService reference
sanghoshin94872a12015-10-16 18:04:34 +090076 */
77 public OpenstackSwitchingRulePopulator(ApplicationId appId,
sanghoshinf25d2e02015-11-11 23:07:17 +090078 FlowObjectiveService flowObjectiveService,
79 DeviceService deviceService,
80 OpenstackRestHandler restHandler,
81 DriverService driverService) {
sanghoshin94872a12015-10-16 18:04:34 +090082 this.flowObjectiveService = flowObjectiveService;
sanghoshinf25d2e02015-11-11 23:07:17 +090083 this.deviceService = deviceService;
84 this.driverService = driverService;
85 this.restHandler = restHandler;
sanghoshin94872a12015-10-16 18:04:34 +090086 this.appId = appId;
sanghoshinf25d2e02015-11-11 23:07:17 +090087
88 openstackNetworkList = restHandler.getNetworks();
89 openstackPortList = restHandler.getPorts();
sanghoshin94872a12015-10-16 18:04:34 +090090 }
91
daniel2a2bd7b2015-12-02 13:53:58 +090092
sanghoshin94872a12015-10-16 18:04:34 +090093 /**
sanghoshinf25d2e02015-11-11 23:07:17 +090094 * Populates flow rules for the VM created.
sanghoshin94872a12015-10-16 18:04:34 +090095 *
sanghoshinf25d2e02015-11-11 23:07:17 +090096 * @param device device to populate rules to
97 * @param port port for the VM created
sanghoshin94872a12015-10-16 18:04:34 +090098 */
sanghoshinf25d2e02015-11-11 23:07:17 +090099 public void populateSwitchingRules(Device device, Port port) {
Hyunsun Moon74ec4062015-12-09 10:58:32 -0800100 populateFlowRulesForTunnelTag(device, port);
sanghoshinf25d2e02015-11-11 23:07:17 +0900101 populateFlowRulesForTrafficToSameCnode(device, port);
102 populateFlowRulesForTrafficToDifferentCnode(device, port);
sanghoshin94872a12015-10-16 18:04:34 +0900103 }
104
105 /**
daniel2a2bd7b2015-12-02 13:53:58 +0900106 * Populate the flow rules for tagging tunnelId according to which inport is came from.
107 *
108 * @param device device to put the rules
109 * @param port port info of the VM
110 */
Hyunsun Moon74ec4062015-12-09 10:58:32 -0800111 private void populateFlowRulesForTunnelTag(Device device, Port port) {
daniel2a2bd7b2015-12-02 13:53:58 +0900112 Ip4Address vmIp = getFixedIpAddressForPort(port.annotations().value("portName"));
113 String portName = port.annotations().value("portName");
114 String vni = getVniForPort(portName);
115
116 if (vmIp != null) {
Hyunsun Moon74ec4062015-12-09 10:58:32 -0800117 setFlowRuleForTunnelTag(device.id(), port, vni);
daniel2a2bd7b2015-12-02 13:53:58 +0900118 }
119 }
120
Daniel Park5df65182016-01-09 00:12:03 +0900121 private void setFlowRuleForTunnelTag(DeviceId deviceId, Port port, String vni) {
sanghoshin075e3e72015-11-25 16:34:29 +0900122
Daniel Park5df65182016-01-09 00:12:03 +0900123 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
124 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
125
126 sBuilder.matchEthType(Ethernet.TYPE_IPV4)
127 .matchInPort(port.number());
128
129 tBuilder.setTunnelId(Long.parseLong(vni));
130
131 ForwardingObjective fo = DefaultForwardingObjective.builder()
132 .withSelector(sBuilder.build())
133 .withTreatment(tBuilder.build())
134 .withPriority(TUNNELTAG_RULE_PRIORITY)
135 .withFlag(ForwardingObjective.Flag.SPECIFIC)
136 .fromApp(appId)
137 .add();
138
139 flowObjectiveService.forward(deviceId, fo);
sanghoshin65723ae2015-11-17 22:07:21 +0900140 }
141
142 /**
sanghoshinf25d2e02015-11-11 23:07:17 +0900143 * Populates the flow rules for traffic to VMs in the same Cnode as the sender.
sanghoshin94872a12015-10-16 18:04:34 +0900144 *
sanghoshinf25d2e02015-11-11 23:07:17 +0900145 * @param device device to put the rules
146 * @param port port info of the VM
sanghoshin94872a12015-10-16 18:04:34 +0900147 */
sanghoshinf25d2e02015-11-11 23:07:17 +0900148 private void populateFlowRulesForTrafficToSameCnode(Device device, Port port) {
149 Ip4Address vmIp = getFixedIpAddressForPort(port.annotations().value("portName"));
daniel2a2bd7b2015-12-02 13:53:58 +0900150 String portName = port.annotations().value("portName");
151 String vni = getVniForPort(portName);
daniel2a2bd7b2015-12-02 13:53:58 +0900152
sanghoshinf25d2e02015-11-11 23:07:17 +0900153 if (vmIp != null) {
Daniel Park5df65182016-01-09 00:12:03 +0900154 setFlowRuleForVMsInSameCnode(vmIp, device.id(), port, vni);
sanghoshinf25d2e02015-11-11 23:07:17 +0900155 }
sanghoshin94872a12015-10-16 18:04:34 +0900156 }
157
158 /**
Daniel Park5df65182016-01-09 00:12:03 +0900159 * Sets the flow rules for traffic between VMs in the same Cnode.
160 *
161 * @param ip4Address VM IP address
162 * @param id device ID to put rules
163 * @param port VM port
164 * @param vni VM VNI
165 */
166 private void setFlowRuleForVMsInSameCnode(Ip4Address ip4Address, DeviceId id,
167 Port port, String vni) {
168
169 //For L2 Switching Case
170 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
171 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
172
173 sBuilder.matchEthType(Ethernet.TYPE_IPV4)
174 .matchIPDst(ip4Address.toIpPrefix())
175 .matchTunnelId(Long.parseLong(vni));
176
177 tBuilder.setOutput(port.number());
178
179 ForwardingObjective fo = DefaultForwardingObjective.builder()
180 .withSelector(sBuilder.build())
181 .withTreatment(tBuilder.build())
182 .withPriority(SWITCHING_RULE_PRIORITY)
183 .withFlag(ForwardingObjective.Flag.SPECIFIC)
184 .fromApp(appId)
185 .add();
186
187 flowObjectiveService.forward(id, fo);
188 }
189
190 /**
sanghoshinf25d2e02015-11-11 23:07:17 +0900191 * Populates the flow rules for traffic to VMs in different Cnode using
192 * Nicira extention.
sanghoshin94872a12015-10-16 18:04:34 +0900193 *
sanghoshinf25d2e02015-11-11 23:07:17 +0900194 * @param device device to put rules
195 * @param port port information of the VM
sanghoshin94872a12015-10-16 18:04:34 +0900196 */
sanghoshinf25d2e02015-11-11 23:07:17 +0900197 private void populateFlowRulesForTrafficToDifferentCnode(Device device, Port port) {
198 String portName = port.annotations().value("portName");
199 String channelId = device.annotations().value("channelId");
200 Ip4Address hostIpAddress = Ip4Address.valueOf(channelId.split(":")[0]);
201 Ip4Address fixedIp = getFixedIpAddressForPort(portName);
sanghoshinf25d2e02015-11-11 23:07:17 +0900202 String vni = getVniForPort(portName);
203 deviceService.getAvailableDevices().forEach(d -> {
204 if (!d.equals(device)) {
205 deviceService.getPorts(d.id()).forEach(p -> {
206 String pName = p.annotations().value("portName");
207 if (!p.equals(port) && vni.equals(getVniForPort(pName))) {
208 String cidx = d.annotations().value("channelId");
209 Ip4Address hostIpx = Ip4Address.valueOf(cidx.split(":")[0]);
sanghoshinf25d2e02015-11-11 23:07:17 +0900210 Ip4Address fixedIpx = getFixedIpAddressForPort(pName);
sanghoshin65723ae2015-11-17 22:07:21 +0900211 if (port.isEnabled()) {
Daniel Park5df65182016-01-09 00:12:03 +0900212 setVxLanFlowRule(vni, device.id(), hostIpx, fixedIpx);
213 setVxLanFlowRule(vni, d.id(), hostIpAddress, fixedIp);
sanghoshin65723ae2015-11-17 22:07:21 +0900214 }
sanghoshinf25d2e02015-11-11 23:07:17 +0900215 }
216 });
217 }
218 });
sanghoshin94872a12015-10-16 18:04:34 +0900219 }
220
221 /**
Daniel Park5df65182016-01-09 00:12:03 +0900222 * Sets the flow rules between traffic from VMs in different Cnode.
223 *
224 * @param vni VNI
225 * @param deviceId device ID
226 * @param hostIp host IP of the VM
227 * @param vmIp fixed IP of the VM
228 */
229 private void setVxLanFlowRule(String vni, DeviceId deviceId, Ip4Address hostIp,
230 Ip4Address vmIp) {
231 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
232 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
233
234 sBuilder.matchEthType(Ethernet.TYPE_IPV4)
235 .matchTunnelId(Long.parseLong(vni))
236 .matchIPDst(vmIp.toIpPrefix());
237 tBuilder.extension(buildNiciraExtenstion(deviceId, hostIp), deviceId)
238 .setOutput(getTunnelPort(deviceId));
239
240 ForwardingObjective fo = DefaultForwardingObjective.builder()
241 .withSelector(sBuilder.build())
242 .withTreatment(tBuilder.build())
243 .withPriority(SWITCHING_RULE_PRIORITY)
244 .withFlag(ForwardingObjective.Flag.SPECIFIC)
245 .fromApp(appId)
246 .add();
247
248 flowObjectiveService.forward(deviceId, fo);
249 }
250
251 /**
252 * Returns OpenstackPort object for the Port reference given.
253 *
254 * @param port Port object
255 * @return OpenstackPort reference, or null when not found
256 */
257 public OpenstackPort openstackPort(Port port) {
258 String uuid = port.annotations().value("portName").substring(3);
259 return openstackPortList.stream().filter(p -> p.id().startsWith(uuid))
260 .findAny().orElse(null);
261 }
262
263 /**
264 * Remove flows rules for the removed VM.
265 *
266 * @param removedPort removedport info
267 * @param openstackPortInfoMap openstackPortInfoMap
268 */
269 public void removeSwitchingRules(Port removedPort, Map<String, OpenstackPortInfo> openstackPortInfoMap) {
270
271 OpenstackPortInfo openstackPortInfo = openstackPortInfoMap
272 .get(removedPort.annotations().value("portName"));
273
274 DeviceId deviceId = openstackPortInfo.deviceId();
275 Ip4Address vmIp = openstackPortInfo.ip();
276 PortNumber portNumber = removedPort.number();
277 long vni = openstackPortInfo.vni();
278
279 removeFlowRuleForTunnelTag(deviceId, portNumber);
280 removeFlowRuleForVMsInSameCnode(deviceId, vmIp, vni);
281 removeFlowRuleForVMsInDiffrentCnode(removedPort, deviceId, vmIp, vni, openstackPortInfoMap);
282 }
283
284 /**
285 * Removes flow rules for tagging tunnelId.
286 *
287 * @param deviceId device id
288 * @param portNumber port number
289 */
290 private void removeFlowRuleForTunnelTag(DeviceId deviceId, PortNumber portNumber) {
291 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
292 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
293
294 sBuilder.matchEthType(Ethernet.TYPE_IPV4)
295 .matchInPort(portNumber);
296
297 ForwardingObjective fo = DefaultForwardingObjective.builder()
298 .withSelector(sBuilder.build())
299 .withTreatment(tBuilder.build())
300 .withPriority(TUNNELTAG_RULE_PRIORITY)
301 .withFlag(ForwardingObjective.Flag.SPECIFIC)
302 .fromApp(appId)
303 .remove();
304
305 flowObjectiveService.forward(deviceId, fo);
306 }
307
308 /**
309 * Removes the flow rules for traffic between VMs in the same Cnode.
310 *
311 * @param deviceId device id on which removed VM was run
312 * @param vmIp ip of the removed VM
313 * @param vni vni which removed VM was belonged
314 */
315 private void removeFlowRuleForVMsInSameCnode(DeviceId deviceId, Ip4Address vmIp, long vni) {
316 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
317
318 sBuilder.matchEthType(Ethernet.TYPE_IPV4)
319 .matchIPDst(vmIp.toIpPrefix())
320 .matchTunnelId(vni);
321
322 ForwardingObjective fo = DefaultForwardingObjective.builder()
323 .withSelector(sBuilder.build())
324 .withTreatment(DefaultTrafficTreatment.builder().build())
325 .withFlag(ForwardingObjective.Flag.SPECIFIC)
326 .withPriority(SWITCHING_RULE_PRIORITY)
327 .fromApp(appId)
328 .remove();
329
330 flowObjectiveService.forward(deviceId, fo);
331 }
332
333 /**
334 * Removes the flow rules for traffic between VMs in the different Cnode.
335 *
336 * @param removedPort removedport info
337 * @param deviceId device id on which removed VM was run
338 * @param vmIp ip of the removed VM
339 * @param vni vni which removed VM was belonged
340 * @param openstackPortInfoMap openstackPortInfoMap
341 */
342 private void removeFlowRuleForVMsInDiffrentCnode(Port removedPort, DeviceId deviceId, Ip4Address vmIp,
343 long vni, Map<String, OpenstackPortInfo> openstackPortInfoMap) {
344
345 final boolean anyPortRemainedInSameCnode
346 = checkIfAnyPortRemainedInSameCnode(removedPort, deviceId, vni, openstackPortInfoMap);
347
348 openstackPortInfoMap.forEach((port, portInfo) -> {
349 if (portInfo.vni() == vni && !portInfo.deviceId().equals(deviceId)) {
350 removeVxLanFlowRule(portInfo.deviceId(), vmIp, vni);
351 if (!anyPortRemainedInSameCnode) {
352 removeVxLanFlowRule(deviceId, portInfo.ip(), vni);
353 }
354 }
355 });
356 }
357
358 /**
359 * Removes the flow rules between traffic from VMs in different Cnode.
360 *
361 * @param deviceId device id
362 * @param vmIp ip
363 * @param vni vni which removed VM was belonged
364 */
365 private void removeVxLanFlowRule(DeviceId deviceId, Ip4Address vmIp, long vni) {
366 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
367
368 sBuilder.matchEthType(Ethernet.TYPE_IPV4)
369 .matchTunnelId(vni)
370 .matchIPDst(vmIp.toIpPrefix());
371
372 ForwardingObjective fo = DefaultForwardingObjective.builder()
373 .withSelector(sBuilder.build())
374 .withTreatment(DefaultTrafficTreatment.builder().build())
375 .withFlag(ForwardingObjective.Flag.SPECIFIC)
376 .withPriority(SWITCHING_RULE_PRIORITY)
377 .fromApp(appId)
378 .remove();
379
380 flowObjectiveService.forward(deviceId, fo);
381 }
382
383 /**
384 * Checks if there is any port remained with same vni at the device, on which the removed VM was run.
385 *
386 * @param removedPort removedport info
387 * @param deviceId device id on which removed VM was run
388 * @param vni vni which removed VM was belonged
389 * @param openstackPortInfoMap openstackPortInfoMap
390 * @return true if there is, false otherwise
391 */
392 private boolean checkIfAnyPortRemainedInSameCnode(Port removedPort, DeviceId deviceId, long vni,
393 Map<String, OpenstackPortInfo> openstackPortInfoMap) {
394
395 for (Map.Entry<String, OpenstackPortInfo> entry : openstackPortInfoMap.entrySet()) {
396 if (!removedPort.annotations().value("portName").equals(entry.getKey())) {
397 if (entry.getValue().vni() == vni && entry.getValue().deviceId().equals(deviceId)) {
398 return true;
399 }
400 }
401 }
402 return false;
403 }
404
405 /**
sanghoshinf25d2e02015-11-11 23:07:17 +0900406 * Returns the VNI of the VM of the port.
sanghoshin94872a12015-10-16 18:04:34 +0900407 *
sanghoshinf25d2e02015-11-11 23:07:17 +0900408 * @param portName VM port
409 * @return VNI
sanghoshin94872a12015-10-16 18:04:34 +0900410 */
sanghoshinf25d2e02015-11-11 23:07:17 +0900411 private String getVniForPort(String portName) {
412 String uuid = portName.substring(3);
413 OpenstackPort port = openstackPortList.stream()
414 .filter(p -> p.id().startsWith(uuid))
415 .findAny().orElse(null);
416 if (port == null) {
daniel2a2bd7b2015-12-02 13:53:58 +0900417 log.debug("No port information for port {}", portName);
sanghoshinf25d2e02015-11-11 23:07:17 +0900418 return null;
419 }
sanghoshin94872a12015-10-16 18:04:34 +0900420
sanghoshinf25d2e02015-11-11 23:07:17 +0900421 OpenstackNetwork network = openstackNetworkList.stream()
422 .filter(n -> n.id().equals(port.networkId()))
423 .findAny().orElse(null);
424 if (network == null) {
Satish K2e2d6352015-11-27 12:02:15 +0530425 log.warn("No VNI information for network {}", port.networkId());
sanghoshinf25d2e02015-11-11 23:07:17 +0900426 return null;
427 }
sanghoshin94872a12015-10-16 18:04:34 +0900428
sanghoshinf25d2e02015-11-11 23:07:17 +0900429 return network.segmentId();
sanghoshin94872a12015-10-16 18:04:34 +0900430 }
431
432 /**
sanghoshinf25d2e02015-11-11 23:07:17 +0900433 * Returns the Fixed IP address of the VM.
sanghoshin94872a12015-10-16 18:04:34 +0900434 *
sanghoshinf25d2e02015-11-11 23:07:17 +0900435 * @param portName VM port info
436 * @return IP address of the VM
sanghoshin94872a12015-10-16 18:04:34 +0900437 */
sanghoshinf25d2e02015-11-11 23:07:17 +0900438 private Ip4Address getFixedIpAddressForPort(String portName) {
sanghoshin94872a12015-10-16 18:04:34 +0900439
sanghoshinf25d2e02015-11-11 23:07:17 +0900440 String uuid = portName.substring(3);
441 OpenstackPort port = openstackPortList.stream()
442 .filter(p -> p.id().startsWith(uuid))
443 .findFirst().orElse(null);
sanghoshin94872a12015-10-16 18:04:34 +0900444
sanghoshinf25d2e02015-11-11 23:07:17 +0900445 if (port == null) {
446 log.error("There is no port information for port name {}", portName);
447 return null;
448 }
sanghoshin94872a12015-10-16 18:04:34 +0900449
sanghoshinf25d2e02015-11-11 23:07:17 +0900450 if (port.fixedIps().isEmpty()) {
451 log.error("There is no fixed IP info in the port information");
452 return null;
453 }
454
455 return (Ip4Address) port.fixedIps().values().toArray()[0];
456 }
457
sanghoshinf25d2e02015-11-11 23:07:17 +0900458 private ExtensionTreatment buildNiciraExtenstion(DeviceId id, Ip4Address hostIp) {
459 Driver driver = driverService.getDriver(id);
460 DriverHandler driverHandler = new DefaultDriverHandler(new DefaultDriverData(driver, id));
461 ExtensionTreatmentResolver resolver = driverHandler.behaviour(ExtensionTreatmentResolver.class);
462
463 ExtensionTreatment extensionInstruction =
464 resolver.getExtensionInstruction(
465 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type());
466
467 try {
468 extensionInstruction.setPropertyValue("tunnelDst", hostIp);
469 } catch (ExtensionPropertyException e) {
470 log.error("Error setting Nicira extension setting {}", e);
471 }
472
473 return extensionInstruction;
474 }
475
Daniel Park5df65182016-01-09 00:12:03 +0900476 private PortNumber getTunnelPort(DeviceId deviceId) {
477 Port port = deviceService.getPorts(deviceId).stream()
sanghoshinf25d2e02015-11-11 23:07:17 +0900478 .filter(p -> p.annotations().value("portName").equals("vxlan"))
479 .findAny().orElse(null);
480
481 if (port == null) {
482 log.error("No TunnelPort was created.");
483 return null;
484 }
485 return port.number();
486 }
sanghoshin94872a12015-10-16 18:04:34 +0900487}