blob: 92c274240e6da4446233c0f257d800809a9b2330 [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
Jian Lidfba7392016-01-22 16:46:58 -080075 * @param restHandler OpenstackRestHandler reference
sanghoshinf25d2e02015-11-11 23:07:17 +090076 * @param driverService DriverService reference
sanghoshin94872a12015-10-16 18:04:34 +090077 */
78 public OpenstackSwitchingRulePopulator(ApplicationId appId,
sanghoshinf25d2e02015-11-11 23:07:17 +090079 FlowObjectiveService flowObjectiveService,
80 DeviceService deviceService,
81 OpenstackRestHandler restHandler,
82 DriverService driverService) {
sanghoshin94872a12015-10-16 18:04:34 +090083 this.flowObjectiveService = flowObjectiveService;
sanghoshinf25d2e02015-11-11 23:07:17 +090084 this.deviceService = deviceService;
85 this.driverService = driverService;
86 this.restHandler = restHandler;
sanghoshin94872a12015-10-16 18:04:34 +090087 this.appId = appId;
sanghoshinf25d2e02015-11-11 23:07:17 +090088
89 openstackNetworkList = restHandler.getNetworks();
90 openstackPortList = restHandler.getPorts();
sanghoshin94872a12015-10-16 18:04:34 +090091 }
92
daniel2a2bd7b2015-12-02 13:53:58 +090093
sanghoshin94872a12015-10-16 18:04:34 +090094 /**
sanghoshinf25d2e02015-11-11 23:07:17 +090095 * Populates flow rules for the VM created.
sanghoshin94872a12015-10-16 18:04:34 +090096 *
sanghoshinf25d2e02015-11-11 23:07:17 +090097 * @param device device to populate rules to
98 * @param port port for the VM created
sanghoshin94872a12015-10-16 18:04:34 +090099 */
sanghoshinf25d2e02015-11-11 23:07:17 +0900100 public void populateSwitchingRules(Device device, Port port) {
Hyunsun Moon74ec4062015-12-09 10:58:32 -0800101 populateFlowRulesForTunnelTag(device, port);
sanghoshinf25d2e02015-11-11 23:07:17 +0900102 populateFlowRulesForTrafficToSameCnode(device, port);
103 populateFlowRulesForTrafficToDifferentCnode(device, port);
sanghoshin94872a12015-10-16 18:04:34 +0900104 }
105
106 /**
daniel2a2bd7b2015-12-02 13:53:58 +0900107 * Populate the flow rules for tagging tunnelId according to which inport is came from.
108 *
109 * @param device device to put the rules
110 * @param port port info of the VM
111 */
Hyunsun Moon74ec4062015-12-09 10:58:32 -0800112 private void populateFlowRulesForTunnelTag(Device device, Port port) {
daniel2a2bd7b2015-12-02 13:53:58 +0900113 Ip4Address vmIp = getFixedIpAddressForPort(port.annotations().value("portName"));
114 String portName = port.annotations().value("portName");
115 String vni = getVniForPort(portName);
116
117 if (vmIp != null) {
Hyunsun Moon74ec4062015-12-09 10:58:32 -0800118 setFlowRuleForTunnelTag(device.id(), port, vni);
daniel2a2bd7b2015-12-02 13:53:58 +0900119 }
120 }
121
Daniel Park5df65182016-01-09 00:12:03 +0900122 private void setFlowRuleForTunnelTag(DeviceId deviceId, Port port, String vni) {
sanghoshin075e3e72015-11-25 16:34:29 +0900123
Daniel Park5df65182016-01-09 00:12:03 +0900124 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
125 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
126
127 sBuilder.matchEthType(Ethernet.TYPE_IPV4)
128 .matchInPort(port.number());
129
130 tBuilder.setTunnelId(Long.parseLong(vni));
131
132 ForwardingObjective fo = DefaultForwardingObjective.builder()
133 .withSelector(sBuilder.build())
134 .withTreatment(tBuilder.build())
135 .withPriority(TUNNELTAG_RULE_PRIORITY)
136 .withFlag(ForwardingObjective.Flag.SPECIFIC)
137 .fromApp(appId)
138 .add();
139
140 flowObjectiveService.forward(deviceId, fo);
sanghoshin65723ae2015-11-17 22:07:21 +0900141 }
142
143 /**
sanghoshinf25d2e02015-11-11 23:07:17 +0900144 * Populates the flow rules for traffic to VMs in the same Cnode as the sender.
sanghoshin94872a12015-10-16 18:04:34 +0900145 *
sanghoshinf25d2e02015-11-11 23:07:17 +0900146 * @param device device to put the rules
147 * @param port port info of the VM
sanghoshin94872a12015-10-16 18:04:34 +0900148 */
sanghoshinf25d2e02015-11-11 23:07:17 +0900149 private void populateFlowRulesForTrafficToSameCnode(Device device, Port port) {
150 Ip4Address vmIp = getFixedIpAddressForPort(port.annotations().value("portName"));
daniel2a2bd7b2015-12-02 13:53:58 +0900151 String portName = port.annotations().value("portName");
152 String vni = getVniForPort(portName);
daniel2a2bd7b2015-12-02 13:53:58 +0900153
sanghoshinf25d2e02015-11-11 23:07:17 +0900154 if (vmIp != null) {
Daniel Park5df65182016-01-09 00:12:03 +0900155 setFlowRuleForVMsInSameCnode(vmIp, device.id(), port, vni);
sanghoshinf25d2e02015-11-11 23:07:17 +0900156 }
sanghoshin94872a12015-10-16 18:04:34 +0900157 }
158
159 /**
Daniel Park5df65182016-01-09 00:12:03 +0900160 * Sets the flow rules for traffic between VMs in the same Cnode.
161 *
162 * @param ip4Address VM IP address
163 * @param id device ID to put rules
164 * @param port VM port
165 * @param vni VM VNI
166 */
167 private void setFlowRuleForVMsInSameCnode(Ip4Address ip4Address, DeviceId id,
168 Port port, String vni) {
169
170 //For L2 Switching Case
171 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
172 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
173
174 sBuilder.matchEthType(Ethernet.TYPE_IPV4)
175 .matchIPDst(ip4Address.toIpPrefix())
176 .matchTunnelId(Long.parseLong(vni));
177
178 tBuilder.setOutput(port.number());
179
180 ForwardingObjective fo = DefaultForwardingObjective.builder()
181 .withSelector(sBuilder.build())
182 .withTreatment(tBuilder.build())
183 .withPriority(SWITCHING_RULE_PRIORITY)
184 .withFlag(ForwardingObjective.Flag.SPECIFIC)
185 .fromApp(appId)
186 .add();
187
188 flowObjectiveService.forward(id, fo);
189 }
190
191 /**
sanghoshinf25d2e02015-11-11 23:07:17 +0900192 * Populates the flow rules for traffic to VMs in different Cnode using
193 * Nicira extention.
sanghoshin94872a12015-10-16 18:04:34 +0900194 *
sanghoshinf25d2e02015-11-11 23:07:17 +0900195 * @param device device to put rules
196 * @param port port information of the VM
sanghoshin94872a12015-10-16 18:04:34 +0900197 */
sanghoshinf25d2e02015-11-11 23:07:17 +0900198 private void populateFlowRulesForTrafficToDifferentCnode(Device device, Port port) {
199 String portName = port.annotations().value("portName");
200 String channelId = device.annotations().value("channelId");
201 Ip4Address hostIpAddress = Ip4Address.valueOf(channelId.split(":")[0]);
202 Ip4Address fixedIp = getFixedIpAddressForPort(portName);
sanghoshinf25d2e02015-11-11 23:07:17 +0900203 String vni = getVniForPort(portName);
204 deviceService.getAvailableDevices().forEach(d -> {
205 if (!d.equals(device)) {
206 deviceService.getPorts(d.id()).forEach(p -> {
207 String pName = p.annotations().value("portName");
208 if (!p.equals(port) && vni.equals(getVniForPort(pName))) {
209 String cidx = d.annotations().value("channelId");
210 Ip4Address hostIpx = Ip4Address.valueOf(cidx.split(":")[0]);
sanghoshinf25d2e02015-11-11 23:07:17 +0900211 Ip4Address fixedIpx = getFixedIpAddressForPort(pName);
sanghoshin46c6e3e2015-12-18 18:42:17 +0900212 if (port.isEnabled() ||
213 port.annotations().value("portName").startsWith(
214 OpenstackSwitchingManager.PORTNAME_PREFIX_ROUTER)) {
Daniel Park5df65182016-01-09 00:12:03 +0900215 setVxLanFlowRule(vni, device.id(), hostIpx, fixedIpx);
216 setVxLanFlowRule(vni, d.id(), hostIpAddress, fixedIp);
sanghoshin65723ae2015-11-17 22:07:21 +0900217 }
sanghoshinf25d2e02015-11-11 23:07:17 +0900218 }
219 });
220 }
221 });
sanghoshin94872a12015-10-16 18:04:34 +0900222 }
223
224 /**
Daniel Park5df65182016-01-09 00:12:03 +0900225 * Sets the flow rules between traffic from VMs in different Cnode.
226 *
227 * @param vni VNI
228 * @param deviceId device ID
229 * @param hostIp host IP of the VM
230 * @param vmIp fixed IP of the VM
231 */
232 private void setVxLanFlowRule(String vni, DeviceId deviceId, Ip4Address hostIp,
233 Ip4Address vmIp) {
234 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
235 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
236
237 sBuilder.matchEthType(Ethernet.TYPE_IPV4)
238 .matchTunnelId(Long.parseLong(vni))
239 .matchIPDst(vmIp.toIpPrefix());
240 tBuilder.extension(buildNiciraExtenstion(deviceId, hostIp), deviceId)
241 .setOutput(getTunnelPort(deviceId));
242
243 ForwardingObjective fo = DefaultForwardingObjective.builder()
244 .withSelector(sBuilder.build())
245 .withTreatment(tBuilder.build())
246 .withPriority(SWITCHING_RULE_PRIORITY)
247 .withFlag(ForwardingObjective.Flag.SPECIFIC)
248 .fromApp(appId)
249 .add();
250
251 flowObjectiveService.forward(deviceId, fo);
252 }
253
254 /**
255 * Returns OpenstackPort object for the Port reference given.
256 *
257 * @param port Port object
258 * @return OpenstackPort reference, or null when not found
259 */
260 public OpenstackPort openstackPort(Port port) {
261 String uuid = port.annotations().value("portName").substring(3);
262 return openstackPortList.stream().filter(p -> p.id().startsWith(uuid))
263 .findAny().orElse(null);
264 }
265
266 /**
267 * Remove flows rules for the removed VM.
268 *
269 * @param removedPort removedport info
270 * @param openstackPortInfoMap openstackPortInfoMap
271 */
272 public void removeSwitchingRules(Port removedPort, Map<String, OpenstackPortInfo> openstackPortInfoMap) {
273
274 OpenstackPortInfo openstackPortInfo = openstackPortInfoMap
275 .get(removedPort.annotations().value("portName"));
276
277 DeviceId deviceId = openstackPortInfo.deviceId();
278 Ip4Address vmIp = openstackPortInfo.ip();
279 PortNumber portNumber = removedPort.number();
280 long vni = openstackPortInfo.vni();
281
282 removeFlowRuleForTunnelTag(deviceId, portNumber);
283 removeFlowRuleForVMsInSameCnode(deviceId, vmIp, vni);
284 removeFlowRuleForVMsInDiffrentCnode(removedPort, deviceId, vmIp, vni, openstackPortInfoMap);
285 }
286
287 /**
288 * Removes flow rules for tagging tunnelId.
289 *
290 * @param deviceId device id
291 * @param portNumber port number
292 */
293 private void removeFlowRuleForTunnelTag(DeviceId deviceId, PortNumber portNumber) {
294 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
295 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
296
297 sBuilder.matchEthType(Ethernet.TYPE_IPV4)
298 .matchInPort(portNumber);
299
300 ForwardingObjective fo = DefaultForwardingObjective.builder()
301 .withSelector(sBuilder.build())
302 .withTreatment(tBuilder.build())
303 .withPriority(TUNNELTAG_RULE_PRIORITY)
304 .withFlag(ForwardingObjective.Flag.SPECIFIC)
305 .fromApp(appId)
306 .remove();
307
308 flowObjectiveService.forward(deviceId, fo);
309 }
310
311 /**
312 * Removes the flow rules for traffic between VMs in the same Cnode.
313 *
314 * @param deviceId device id on which removed VM was run
315 * @param vmIp ip of the removed VM
316 * @param vni vni which removed VM was belonged
317 */
318 private void removeFlowRuleForVMsInSameCnode(DeviceId deviceId, Ip4Address vmIp, long vni) {
319 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
320
321 sBuilder.matchEthType(Ethernet.TYPE_IPV4)
322 .matchIPDst(vmIp.toIpPrefix())
323 .matchTunnelId(vni);
324
325 ForwardingObjective fo = DefaultForwardingObjective.builder()
326 .withSelector(sBuilder.build())
327 .withTreatment(DefaultTrafficTreatment.builder().build())
328 .withFlag(ForwardingObjective.Flag.SPECIFIC)
329 .withPriority(SWITCHING_RULE_PRIORITY)
330 .fromApp(appId)
331 .remove();
332
333 flowObjectiveService.forward(deviceId, fo);
334 }
335
336 /**
337 * Removes the flow rules for traffic between VMs in the different Cnode.
338 *
339 * @param removedPort removedport info
340 * @param deviceId device id on which removed VM was run
341 * @param vmIp ip of the removed VM
342 * @param vni vni which removed VM was belonged
343 * @param openstackPortInfoMap openstackPortInfoMap
344 */
345 private void removeFlowRuleForVMsInDiffrentCnode(Port removedPort, DeviceId deviceId, Ip4Address vmIp,
346 long vni, Map<String, OpenstackPortInfo> openstackPortInfoMap) {
347
348 final boolean anyPortRemainedInSameCnode
349 = checkIfAnyPortRemainedInSameCnode(removedPort, deviceId, vni, openstackPortInfoMap);
350
351 openstackPortInfoMap.forEach((port, portInfo) -> {
352 if (portInfo.vni() == vni && !portInfo.deviceId().equals(deviceId)) {
353 removeVxLanFlowRule(portInfo.deviceId(), vmIp, vni);
354 if (!anyPortRemainedInSameCnode) {
355 removeVxLanFlowRule(deviceId, portInfo.ip(), vni);
356 }
357 }
358 });
359 }
360
361 /**
362 * Removes the flow rules between traffic from VMs in different Cnode.
363 *
364 * @param deviceId device id
365 * @param vmIp ip
366 * @param vni vni which removed VM was belonged
367 */
368 private void removeVxLanFlowRule(DeviceId deviceId, Ip4Address vmIp, long vni) {
369 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
370
371 sBuilder.matchEthType(Ethernet.TYPE_IPV4)
372 .matchTunnelId(vni)
373 .matchIPDst(vmIp.toIpPrefix());
374
375 ForwardingObjective fo = DefaultForwardingObjective.builder()
376 .withSelector(sBuilder.build())
377 .withTreatment(DefaultTrafficTreatment.builder().build())
378 .withFlag(ForwardingObjective.Flag.SPECIFIC)
379 .withPriority(SWITCHING_RULE_PRIORITY)
380 .fromApp(appId)
381 .remove();
382
383 flowObjectiveService.forward(deviceId, fo);
384 }
385
386 /**
387 * Checks if there is any port remained with same vni at the device, on which the removed VM was run.
388 *
389 * @param removedPort removedport info
390 * @param deviceId device id on which removed VM was run
391 * @param vni vni which removed VM was belonged
392 * @param openstackPortInfoMap openstackPortInfoMap
393 * @return true if there is, false otherwise
394 */
395 private boolean checkIfAnyPortRemainedInSameCnode(Port removedPort, DeviceId deviceId, long vni,
396 Map<String, OpenstackPortInfo> openstackPortInfoMap) {
397
398 for (Map.Entry<String, OpenstackPortInfo> entry : openstackPortInfoMap.entrySet()) {
399 if (!removedPort.annotations().value("portName").equals(entry.getKey())) {
400 if (entry.getValue().vni() == vni && entry.getValue().deviceId().equals(deviceId)) {
401 return true;
402 }
403 }
404 }
405 return false;
406 }
407
408 /**
sanghoshinf25d2e02015-11-11 23:07:17 +0900409 * Returns the VNI of the VM of the port.
sanghoshin94872a12015-10-16 18:04:34 +0900410 *
sanghoshinf25d2e02015-11-11 23:07:17 +0900411 * @param portName VM port
412 * @return VNI
sanghoshin94872a12015-10-16 18:04:34 +0900413 */
sanghoshinf25d2e02015-11-11 23:07:17 +0900414 private String getVniForPort(String portName) {
415 String uuid = portName.substring(3);
416 OpenstackPort port = openstackPortList.stream()
417 .filter(p -> p.id().startsWith(uuid))
418 .findAny().orElse(null);
419 if (port == null) {
daniel2a2bd7b2015-12-02 13:53:58 +0900420 log.debug("No port information for port {}", portName);
sanghoshinf25d2e02015-11-11 23:07:17 +0900421 return null;
422 }
sanghoshin94872a12015-10-16 18:04:34 +0900423
sanghoshinf25d2e02015-11-11 23:07:17 +0900424 OpenstackNetwork network = openstackNetworkList.stream()
425 .filter(n -> n.id().equals(port.networkId()))
426 .findAny().orElse(null);
427 if (network == null) {
Satish K2e2d6352015-11-27 12:02:15 +0530428 log.warn("No VNI information for network {}", port.networkId());
sanghoshinf25d2e02015-11-11 23:07:17 +0900429 return null;
430 }
sanghoshin94872a12015-10-16 18:04:34 +0900431
sanghoshinf25d2e02015-11-11 23:07:17 +0900432 return network.segmentId();
sanghoshin94872a12015-10-16 18:04:34 +0900433 }
434
435 /**
sanghoshinf25d2e02015-11-11 23:07:17 +0900436 * Returns the Fixed IP address of the VM.
sanghoshin94872a12015-10-16 18:04:34 +0900437 *
sanghoshinf25d2e02015-11-11 23:07:17 +0900438 * @param portName VM port info
439 * @return IP address of the VM
sanghoshin94872a12015-10-16 18:04:34 +0900440 */
sanghoshinf25d2e02015-11-11 23:07:17 +0900441 private Ip4Address getFixedIpAddressForPort(String portName) {
sanghoshin94872a12015-10-16 18:04:34 +0900442
sanghoshinf25d2e02015-11-11 23:07:17 +0900443 String uuid = portName.substring(3);
444 OpenstackPort port = openstackPortList.stream()
445 .filter(p -> p.id().startsWith(uuid))
446 .findFirst().orElse(null);
sanghoshin94872a12015-10-16 18:04:34 +0900447
sanghoshinf25d2e02015-11-11 23:07:17 +0900448 if (port == null) {
449 log.error("There is no port information for port name {}", portName);
450 return null;
451 }
sanghoshin94872a12015-10-16 18:04:34 +0900452
sanghoshinf25d2e02015-11-11 23:07:17 +0900453 if (port.fixedIps().isEmpty()) {
454 log.error("There is no fixed IP info in the port information");
455 return null;
456 }
457
458 return (Ip4Address) port.fixedIps().values().toArray()[0];
459 }
460
sanghoshinf25d2e02015-11-11 23:07:17 +0900461 private ExtensionTreatment buildNiciraExtenstion(DeviceId id, Ip4Address hostIp) {
462 Driver driver = driverService.getDriver(id);
463 DriverHandler driverHandler = new DefaultDriverHandler(new DefaultDriverData(driver, id));
464 ExtensionTreatmentResolver resolver = driverHandler.behaviour(ExtensionTreatmentResolver.class);
465
466 ExtensionTreatment extensionInstruction =
467 resolver.getExtensionInstruction(
468 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type());
469
470 try {
471 extensionInstruction.setPropertyValue("tunnelDst", hostIp);
472 } catch (ExtensionPropertyException e) {
473 log.error("Error setting Nicira extension setting {}", e);
474 }
475
476 return extensionInstruction;
477 }
478
Daniel Park5df65182016-01-09 00:12:03 +0900479 private PortNumber getTunnelPort(DeviceId deviceId) {
480 Port port = deviceService.getPorts(deviceId).stream()
sanghoshin46c6e3e2015-12-18 18:42:17 +0900481 .filter(p -> p.annotations().value("portName").equals(
482 OpenstackSwitchingManager.PORTNAME_PREFIX_TUNNEL))
sanghoshinf25d2e02015-11-11 23:07:17 +0900483 .findAny().orElse(null);
484
485 if (port == null) {
486 log.error("No TunnelPort was created.");
487 return null;
488 }
489 return port.number();
490 }
sanghoshin94872a12015-10-16 18:04:34 +0900491}