blob: 014eeb89ba9e63bf6dd2366c360d31c14de04ddf [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);
sanghoshin46c6e3e2015-12-18 18:42:17 +0900211 if (port.isEnabled() ||
212 port.annotations().value("portName").startsWith(
213 OpenstackSwitchingManager.PORTNAME_PREFIX_ROUTER)) {
Daniel Park5df65182016-01-09 00:12:03 +0900214 setVxLanFlowRule(vni, device.id(), hostIpx, fixedIpx);
215 setVxLanFlowRule(vni, d.id(), hostIpAddress, fixedIp);
sanghoshin65723ae2015-11-17 22:07:21 +0900216 }
sanghoshinf25d2e02015-11-11 23:07:17 +0900217 }
218 });
219 }
220 });
sanghoshin94872a12015-10-16 18:04:34 +0900221 }
222
223 /**
Daniel Park5df65182016-01-09 00:12:03 +0900224 * Sets the flow rules between traffic from VMs in different Cnode.
225 *
226 * @param vni VNI
227 * @param deviceId device ID
228 * @param hostIp host IP of the VM
229 * @param vmIp fixed IP of the VM
230 */
231 private void setVxLanFlowRule(String vni, DeviceId deviceId, Ip4Address hostIp,
232 Ip4Address vmIp) {
233 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
234 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
235
236 sBuilder.matchEthType(Ethernet.TYPE_IPV4)
237 .matchTunnelId(Long.parseLong(vni))
238 .matchIPDst(vmIp.toIpPrefix());
239 tBuilder.extension(buildNiciraExtenstion(deviceId, hostIp), deviceId)
240 .setOutput(getTunnelPort(deviceId));
241
242 ForwardingObjective fo = DefaultForwardingObjective.builder()
243 .withSelector(sBuilder.build())
244 .withTreatment(tBuilder.build())
245 .withPriority(SWITCHING_RULE_PRIORITY)
246 .withFlag(ForwardingObjective.Flag.SPECIFIC)
247 .fromApp(appId)
248 .add();
249
250 flowObjectiveService.forward(deviceId, fo);
251 }
252
253 /**
254 * Returns OpenstackPort object for the Port reference given.
255 *
256 * @param port Port object
257 * @return OpenstackPort reference, or null when not found
258 */
259 public OpenstackPort openstackPort(Port port) {
260 String uuid = port.annotations().value("portName").substring(3);
261 return openstackPortList.stream().filter(p -> p.id().startsWith(uuid))
262 .findAny().orElse(null);
263 }
264
265 /**
266 * Remove flows rules for the removed VM.
267 *
268 * @param removedPort removedport info
269 * @param openstackPortInfoMap openstackPortInfoMap
270 */
271 public void removeSwitchingRules(Port removedPort, Map<String, OpenstackPortInfo> openstackPortInfoMap) {
272
273 OpenstackPortInfo openstackPortInfo = openstackPortInfoMap
274 .get(removedPort.annotations().value("portName"));
275
276 DeviceId deviceId = openstackPortInfo.deviceId();
277 Ip4Address vmIp = openstackPortInfo.ip();
278 PortNumber portNumber = removedPort.number();
279 long vni = openstackPortInfo.vni();
280
281 removeFlowRuleForTunnelTag(deviceId, portNumber);
282 removeFlowRuleForVMsInSameCnode(deviceId, vmIp, vni);
283 removeFlowRuleForVMsInDiffrentCnode(removedPort, deviceId, vmIp, vni, openstackPortInfoMap);
284 }
285
286 /**
287 * Removes flow rules for tagging tunnelId.
288 *
289 * @param deviceId device id
290 * @param portNumber port number
291 */
292 private void removeFlowRuleForTunnelTag(DeviceId deviceId, PortNumber portNumber) {
293 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
294 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
295
296 sBuilder.matchEthType(Ethernet.TYPE_IPV4)
297 .matchInPort(portNumber);
298
299 ForwardingObjective fo = DefaultForwardingObjective.builder()
300 .withSelector(sBuilder.build())
301 .withTreatment(tBuilder.build())
302 .withPriority(TUNNELTAG_RULE_PRIORITY)
303 .withFlag(ForwardingObjective.Flag.SPECIFIC)
304 .fromApp(appId)
305 .remove();
306
307 flowObjectiveService.forward(deviceId, fo);
308 }
309
310 /**
311 * Removes the flow rules for traffic between VMs in the same Cnode.
312 *
313 * @param deviceId device id on which removed VM was run
314 * @param vmIp ip of the removed VM
315 * @param vni vni which removed VM was belonged
316 */
317 private void removeFlowRuleForVMsInSameCnode(DeviceId deviceId, Ip4Address vmIp, long vni) {
318 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
319
320 sBuilder.matchEthType(Ethernet.TYPE_IPV4)
321 .matchIPDst(vmIp.toIpPrefix())
322 .matchTunnelId(vni);
323
324 ForwardingObjective fo = DefaultForwardingObjective.builder()
325 .withSelector(sBuilder.build())
326 .withTreatment(DefaultTrafficTreatment.builder().build())
327 .withFlag(ForwardingObjective.Flag.SPECIFIC)
328 .withPriority(SWITCHING_RULE_PRIORITY)
329 .fromApp(appId)
330 .remove();
331
332 flowObjectiveService.forward(deviceId, fo);
333 }
334
335 /**
336 * Removes the flow rules for traffic between VMs in the different Cnode.
337 *
338 * @param removedPort removedport info
339 * @param deviceId device id on which removed VM was run
340 * @param vmIp ip of the removed VM
341 * @param vni vni which removed VM was belonged
342 * @param openstackPortInfoMap openstackPortInfoMap
343 */
344 private void removeFlowRuleForVMsInDiffrentCnode(Port removedPort, DeviceId deviceId, Ip4Address vmIp,
345 long vni, Map<String, OpenstackPortInfo> openstackPortInfoMap) {
346
347 final boolean anyPortRemainedInSameCnode
348 = checkIfAnyPortRemainedInSameCnode(removedPort, deviceId, vni, openstackPortInfoMap);
349
350 openstackPortInfoMap.forEach((port, portInfo) -> {
351 if (portInfo.vni() == vni && !portInfo.deviceId().equals(deviceId)) {
352 removeVxLanFlowRule(portInfo.deviceId(), vmIp, vni);
353 if (!anyPortRemainedInSameCnode) {
354 removeVxLanFlowRule(deviceId, portInfo.ip(), vni);
355 }
356 }
357 });
358 }
359
360 /**
361 * Removes the flow rules between traffic from VMs in different Cnode.
362 *
363 * @param deviceId device id
364 * @param vmIp ip
365 * @param vni vni which removed VM was belonged
366 */
367 private void removeVxLanFlowRule(DeviceId deviceId, Ip4Address vmIp, long vni) {
368 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
369
370 sBuilder.matchEthType(Ethernet.TYPE_IPV4)
371 .matchTunnelId(vni)
372 .matchIPDst(vmIp.toIpPrefix());
373
374 ForwardingObjective fo = DefaultForwardingObjective.builder()
375 .withSelector(sBuilder.build())
376 .withTreatment(DefaultTrafficTreatment.builder().build())
377 .withFlag(ForwardingObjective.Flag.SPECIFIC)
378 .withPriority(SWITCHING_RULE_PRIORITY)
379 .fromApp(appId)
380 .remove();
381
382 flowObjectiveService.forward(deviceId, fo);
383 }
384
385 /**
386 * Checks if there is any port remained with same vni at the device, on which the removed VM was run.
387 *
388 * @param removedPort removedport info
389 * @param deviceId device id on which removed VM was run
390 * @param vni vni which removed VM was belonged
391 * @param openstackPortInfoMap openstackPortInfoMap
392 * @return true if there is, false otherwise
393 */
394 private boolean checkIfAnyPortRemainedInSameCnode(Port removedPort, DeviceId deviceId, long vni,
395 Map<String, OpenstackPortInfo> openstackPortInfoMap) {
396
397 for (Map.Entry<String, OpenstackPortInfo> entry : openstackPortInfoMap.entrySet()) {
398 if (!removedPort.annotations().value("portName").equals(entry.getKey())) {
399 if (entry.getValue().vni() == vni && entry.getValue().deviceId().equals(deviceId)) {
400 return true;
401 }
402 }
403 }
404 return false;
405 }
406
407 /**
sanghoshinf25d2e02015-11-11 23:07:17 +0900408 * Returns the VNI of the VM of the port.
sanghoshin94872a12015-10-16 18:04:34 +0900409 *
sanghoshinf25d2e02015-11-11 23:07:17 +0900410 * @param portName VM port
411 * @return VNI
sanghoshin94872a12015-10-16 18:04:34 +0900412 */
sanghoshinf25d2e02015-11-11 23:07:17 +0900413 private String getVniForPort(String portName) {
414 String uuid = portName.substring(3);
415 OpenstackPort port = openstackPortList.stream()
416 .filter(p -> p.id().startsWith(uuid))
417 .findAny().orElse(null);
418 if (port == null) {
daniel2a2bd7b2015-12-02 13:53:58 +0900419 log.debug("No port information for port {}", portName);
sanghoshinf25d2e02015-11-11 23:07:17 +0900420 return null;
421 }
sanghoshin94872a12015-10-16 18:04:34 +0900422
sanghoshinf25d2e02015-11-11 23:07:17 +0900423 OpenstackNetwork network = openstackNetworkList.stream()
424 .filter(n -> n.id().equals(port.networkId()))
425 .findAny().orElse(null);
426 if (network == null) {
Satish K2e2d6352015-11-27 12:02:15 +0530427 log.warn("No VNI information for network {}", port.networkId());
sanghoshinf25d2e02015-11-11 23:07:17 +0900428 return null;
429 }
sanghoshin94872a12015-10-16 18:04:34 +0900430
sanghoshinf25d2e02015-11-11 23:07:17 +0900431 return network.segmentId();
sanghoshin94872a12015-10-16 18:04:34 +0900432 }
433
434 /**
sanghoshinf25d2e02015-11-11 23:07:17 +0900435 * Returns the Fixed IP address of the VM.
sanghoshin94872a12015-10-16 18:04:34 +0900436 *
sanghoshinf25d2e02015-11-11 23:07:17 +0900437 * @param portName VM port info
438 * @return IP address of the VM
sanghoshin94872a12015-10-16 18:04:34 +0900439 */
sanghoshinf25d2e02015-11-11 23:07:17 +0900440 private Ip4Address getFixedIpAddressForPort(String portName) {
sanghoshin94872a12015-10-16 18:04:34 +0900441
sanghoshinf25d2e02015-11-11 23:07:17 +0900442 String uuid = portName.substring(3);
443 OpenstackPort port = openstackPortList.stream()
444 .filter(p -> p.id().startsWith(uuid))
445 .findFirst().orElse(null);
sanghoshin94872a12015-10-16 18:04:34 +0900446
sanghoshinf25d2e02015-11-11 23:07:17 +0900447 if (port == null) {
448 log.error("There is no port information for port name {}", portName);
449 return null;
450 }
sanghoshin94872a12015-10-16 18:04:34 +0900451
sanghoshinf25d2e02015-11-11 23:07:17 +0900452 if (port.fixedIps().isEmpty()) {
453 log.error("There is no fixed IP info in the port information");
454 return null;
455 }
456
457 return (Ip4Address) port.fixedIps().values().toArray()[0];
458 }
459
sanghoshinf25d2e02015-11-11 23:07:17 +0900460 private ExtensionTreatment buildNiciraExtenstion(DeviceId id, Ip4Address hostIp) {
461 Driver driver = driverService.getDriver(id);
462 DriverHandler driverHandler = new DefaultDriverHandler(new DefaultDriverData(driver, id));
463 ExtensionTreatmentResolver resolver = driverHandler.behaviour(ExtensionTreatmentResolver.class);
464
465 ExtensionTreatment extensionInstruction =
466 resolver.getExtensionInstruction(
467 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type());
468
469 try {
470 extensionInstruction.setPropertyValue("tunnelDst", hostIp);
471 } catch (ExtensionPropertyException e) {
472 log.error("Error setting Nicira extension setting {}", e);
473 }
474
475 return extensionInstruction;
476 }
477
Daniel Park5df65182016-01-09 00:12:03 +0900478 private PortNumber getTunnelPort(DeviceId deviceId) {
479 Port port = deviceService.getPorts(deviceId).stream()
sanghoshin46c6e3e2015-12-18 18:42:17 +0900480 .filter(p -> p.annotations().value("portName").equals(
481 OpenstackSwitchingManager.PORTNAME_PREFIX_TUNNEL))
sanghoshinf25d2e02015-11-11 23:07:17 +0900482 .findAny().orElse(null);
483
484 if (port == null) {
485 log.error("No TunnelPort was created.");
486 return null;
487 }
488 return port.number();
489 }
sanghoshin94872a12015-10-16 18:04:34 +0900490}