sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 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.openstacknetworking.routing; |
| 17 | |
| 18 | import org.onlab.packet.Ethernet; |
| 19 | import org.onlab.packet.IPv4; |
| 20 | import org.onlab.packet.Ip4Address; |
| 21 | import org.onlab.packet.IpAddress; |
| 22 | import org.onlab.packet.IpPrefix; |
| 23 | import org.onlab.packet.MacAddress; |
| 24 | import org.onlab.packet.TCP; |
| 25 | import org.onlab.packet.TpPort; |
| 26 | import org.onlab.packet.UDP; |
| 27 | import org.onosproject.core.ApplicationId; |
| 28 | import org.onosproject.net.Device; |
| 29 | import org.onosproject.net.DeviceId; |
| 30 | import org.onosproject.net.Port; |
| 31 | import org.onosproject.net.PortNumber; |
| 32 | import org.onosproject.net.behaviour.ExtensionTreatmentResolver; |
| 33 | import org.onosproject.net.device.DeviceService; |
| 34 | import org.onosproject.net.driver.DefaultDriverData; |
| 35 | import org.onosproject.net.driver.DefaultDriverHandler; |
| 36 | import org.onosproject.net.driver.Driver; |
| 37 | import org.onosproject.net.driver.DriverHandler; |
| 38 | import org.onosproject.net.driver.DriverService; |
| 39 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 40 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 41 | import org.onosproject.net.flow.TrafficSelector; |
| 42 | import org.onosproject.net.flow.TrafficTreatment; |
| 43 | import org.onosproject.net.flow.instructions.ExtensionPropertyException; |
| 44 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
| 45 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
| 46 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 47 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 48 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 49 | import org.onosproject.net.packet.InboundPacket; |
sangho | 93447f1 | 2016-02-24 00:33:22 +0900 | [diff] [blame] | 50 | import org.onosproject.openstackinterface.OpenstackInterfaceService; |
| 51 | import org.onosproject.openstackinterface.OpenstackPort; |
sangho | 93447f1 | 2016-02-24 00:33:22 +0900 | [diff] [blame] | 52 | import org.onosproject.openstackinterface.OpenstackRouterInterface; |
| 53 | import org.onosproject.openstackinterface.OpenstackSubnet; |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 54 | import org.onosproject.openstackinterface.OpenstackFloatingIP; |
sangho | 4890754 | 2016-03-28 16:07:07 +0900 | [diff] [blame] | 55 | import org.onosproject.openstacknetworking.OpenstackNetworkingConfig; |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 56 | import org.onosproject.openstacknetworking.OpenstackPortInfo; |
Kyuhwi Choi | 5e65e2c | 2016-04-01 11:48:15 +0900 | [diff] [blame^] | 57 | import org.onosproject.openstacknetworking.OpenstackRoutingService; |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 58 | import org.slf4j.Logger; |
| 59 | import org.slf4j.LoggerFactory; |
| 60 | |
Kyuhwi Choi | 5e65e2c | 2016-04-01 11:48:15 +0900 | [diff] [blame^] | 61 | import java.util.List; |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 62 | import java.util.stream.StreamSupport; |
| 63 | |
| 64 | import static com.google.common.base.Preconditions.checkNotNull; |
Kyuhwi Choi | 5e65e2c | 2016-04-01 11:48:15 +0900 | [diff] [blame^] | 65 | import static org.onlab.osgi.DefaultServiceDirectory.getService; |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * Populates Routing Flow Rules. |
| 69 | */ |
| 70 | public class OpenstackRoutingRulePopulator { |
| 71 | |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 72 | private final Logger log = LoggerFactory.getLogger(getClass()); |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 73 | |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 74 | private final ApplicationId appId; |
| 75 | private final FlowObjectiveService flowObjectiveService; |
sangho | 93447f1 | 2016-02-24 00:33:22 +0900 | [diff] [blame] | 76 | private final OpenstackInterfaceService openstackService; |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 77 | private final DeviceService deviceService; |
| 78 | private final DriverService driverService; |
sangho | 4890754 | 2016-03-28 16:07:07 +0900 | [diff] [blame] | 79 | private final OpenstackNetworkingConfig config; |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 80 | |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 81 | private static final String PORTNAME_PREFIX_TUNNEL = "vxlan"; |
| 82 | private static final String PORTNAME = "portName"; |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 83 | private static final String PORTNAME_PREFIX_VM = "tap"; |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 84 | |
| 85 | private static final String PORTNOTNULL = "Port can not be null"; |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 86 | private static final String DEVICENOTNULL = "Device can not be null"; |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 87 | private static final String TUNNEL_DESTINATION = "tunnelDst"; |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 88 | private static final int ROUTING_RULE_PRIORITY = 25000; |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 89 | private static final int FLOATING_RULE_PRIORITY = 42000; |
| 90 | private static final int PNAT_RULE_PRIORITY = 26000; |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 91 | private static final int PNAT_TIMEOUT = 120; |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 92 | private static final int PREFIX_LENGTH = 32; |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 93 | private static final MacAddress GATEWAYMAC = MacAddress.valueOf("1f:1f:1f:1f:1f:1f"); |
| 94 | |
| 95 | private InboundPacket inboundPacket; |
| 96 | private OpenstackPort openstackPort; |
| 97 | private int portNum; |
| 98 | private MacAddress externalInterface; |
| 99 | private MacAddress externalRouter; |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 100 | |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 101 | /** |
| 102 | * The constructor of openstackRoutingRulePopulator. |
| 103 | * |
| 104 | * @param appId Caller`s appId |
Kyuhwi Choi | 5e65e2c | 2016-04-01 11:48:15 +0900 | [diff] [blame^] | 105 | * @param openstackService Opestack REST request handler |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 106 | * @param flowObjectiveService FlowObjectiveService |
| 107 | * @param deviceService DeviceService |
| 108 | * @param driverService DriverService |
Kyuhwi Choi | 5e65e2c | 2016-04-01 11:48:15 +0900 | [diff] [blame^] | 109 | * @param config Configuration for openstack environment |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 110 | */ |
sangho | 93447f1 | 2016-02-24 00:33:22 +0900 | [diff] [blame] | 111 | public OpenstackRoutingRulePopulator(ApplicationId appId, OpenstackInterfaceService openstackService, |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 112 | FlowObjectiveService flowObjectiveService, DeviceService deviceService, |
sangho | 4890754 | 2016-03-28 16:07:07 +0900 | [diff] [blame] | 113 | DriverService driverService, OpenstackNetworkingConfig config) { |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 114 | this.appId = appId; |
| 115 | this.flowObjectiveService = flowObjectiveService; |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 116 | this.openstackService = checkNotNull(openstackService); |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 117 | this.deviceService = deviceService; |
| 118 | this.driverService = driverService; |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 119 | this.config = config; |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 120 | } |
| 121 | |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 122 | /** |
| 123 | * Populates flow rules for Pnat configurations. |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 124 | * |
| 125 | * @param inboundPacket Packet-in event packet |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 126 | * @param openstackPort Target VM information |
| 127 | * @param portNum Pnat port number |
Hyunsun Moon | 0dba61f | 2016-03-03 14:05:21 -0800 | [diff] [blame] | 128 | * @param externalIp external ip address |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 129 | * @param externalInterfaceMacAddress Gateway external interface macaddress |
| 130 | * @param externalRouterMacAddress Outer(physical) router`s macaddress |
| 131 | */ |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 132 | public void populatePnatFlowRules(InboundPacket inboundPacket, OpenstackPort openstackPort, int portNum, |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 133 | Ip4Address externalIp, MacAddress externalInterfaceMacAddress, |
| 134 | MacAddress externalRouterMacAddress) { |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 135 | this.inboundPacket = inboundPacket; |
| 136 | this.openstackPort = openstackPort; |
| 137 | this.portNum = portNum; |
| 138 | this.externalInterface = externalInterfaceMacAddress; |
| 139 | this.externalRouter = externalRouterMacAddress; |
| 140 | |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 141 | long vni = getVni(openstackPort.networkId()); |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 142 | |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 143 | populatePnatIncomingFlowRules(vni, externalIp); |
| 144 | populatePnatOutgoingFlowRules(vni, externalIp); |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 145 | } |
| 146 | |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 147 | private void populatePnatOutgoingFlowRules(long vni, Ip4Address externalIp) { |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 148 | IPv4 iPacket = (IPv4) inboundPacket.parsed().getPayload(); |
| 149 | |
| 150 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 151 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) |
| 152 | .matchIPProtocol(iPacket.getProtocol()) |
| 153 | .matchTunnelId(vni) |
| 154 | .matchIPSrc(IpPrefix.valueOf(iPacket.getSourceAddress(), 32)) |
| 155 | .matchIPDst(IpPrefix.valueOf(iPacket.getDestinationAddress(), 32)); |
| 156 | |
| 157 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 158 | tBuilder.setEthSrc(externalInterface) |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 159 | .setEthDst(externalRouter) |
| 160 | .setIpSrc(externalIp); |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 161 | |
| 162 | switch (iPacket.getProtocol()) { |
| 163 | case IPv4.PROTOCOL_TCP: |
| 164 | TCP tcpPacket = (TCP) iPacket.getPayload(); |
| 165 | sBuilder.matchTcpSrc(TpPort.tpPort(tcpPacket.getSourcePort())) |
| 166 | .matchTcpDst(TpPort.tpPort(tcpPacket.getDestinationPort())); |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 167 | tBuilder.setTcpSrc(TpPort.tpPort(portNum)); |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 168 | break; |
| 169 | case IPv4.PROTOCOL_UDP: |
| 170 | UDP udpPacket = (UDP) iPacket.getPayload(); |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 171 | sBuilder.matchUdpSrc(TpPort.tpPort(udpPacket.getSourcePort())) |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 172 | .matchUdpDst(TpPort.tpPort(udpPacket.getDestinationPort())); |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 173 | tBuilder.setUdpSrc(TpPort.tpPort(portNum)); |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 174 | break; |
| 175 | default: |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 176 | log.debug("Unsupported IPv4 protocol {}"); |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 177 | break; |
| 178 | } |
| 179 | |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 180 | Port port = checkNotNull(getPortOfExternalInterface(), PORTNOTNULL); |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 181 | tBuilder.setOutput(port.number()); |
| 182 | |
| 183 | ForwardingObjective fo = DefaultForwardingObjective.builder() |
| 184 | .withSelector(sBuilder.build()) |
| 185 | .withTreatment(tBuilder.build()) |
| 186 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 187 | .withPriority(PNAT_RULE_PRIORITY) |
| 188 | .makeTemporary(PNAT_TIMEOUT) |
| 189 | .fromApp(appId) |
| 190 | .add(); |
| 191 | |
| 192 | flowObjectiveService.forward(inboundPacket.receivedFrom().deviceId(), fo); |
Kyuhwi Choi | 5e65e2c | 2016-04-01 11:48:15 +0900 | [diff] [blame^] | 193 | |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 194 | } |
| 195 | |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 196 | private Port getPortOfExternalInterface() { |
| 197 | return deviceService.getPorts(getGatewayNode().id()).stream() |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 198 | .filter(p -> p.annotations().value(PORTNAME).equals(config.gatewayExternalInterfaceName())) |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 199 | .findAny().orElse(null); |
| 200 | } |
| 201 | |
| 202 | |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 203 | private void populatePnatIncomingFlowRules(long vni, Ip4Address externalIp) { |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 204 | IPv4 iPacket = (IPv4) inboundPacket.parsed().getPayload(); |
| 205 | DeviceId deviceId = inboundPacket.receivedFrom().deviceId(); |
| 206 | |
| 207 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 208 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) |
| 209 | .matchIPProtocol(iPacket.getProtocol()) |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 210 | .matchIPDst(IpPrefix.valueOf(externalIp, 32)) |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 211 | .matchIPSrc(IpPrefix.valueOf(iPacket.getDestinationAddress(), 32)); |
| 212 | |
| 213 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 214 | tBuilder.setTunnelId(vni) |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 215 | .setEthDst(inboundPacket.parsed().getSourceMAC()) |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 216 | .setIpDst(IpAddress.valueOf(iPacket.getSourceAddress())); |
| 217 | |
| 218 | switch (iPacket.getProtocol()) { |
| 219 | case IPv4.PROTOCOL_TCP: |
| 220 | TCP tcpPacket = (TCP) iPacket.getPayload(); |
| 221 | sBuilder.matchTcpSrc(TpPort.tpPort(tcpPacket.getDestinationPort())) |
| 222 | .matchTcpDst(TpPort.tpPort(portNum)); |
| 223 | tBuilder.setTcpDst(TpPort.tpPort(tcpPacket.getSourcePort())); |
| 224 | break; |
| 225 | case IPv4.PROTOCOL_UDP: |
| 226 | UDP udpPacket = (UDP) iPacket.getPayload(); |
| 227 | sBuilder.matchUdpSrc(TpPort.tpPort(udpPacket.getDestinationPort())) |
| 228 | .matchUdpDst(TpPort.tpPort(portNum)); |
| 229 | tBuilder.setUdpDst(TpPort.tpPort(udpPacket.getSourcePort())); |
| 230 | break; |
| 231 | default: |
| 232 | break; |
| 233 | } |
| 234 | |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 235 | tBuilder.extension(buildNiciraExtenstion(deviceId, getHostIpfromOpenstackPort(openstackPort)), deviceId) |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 236 | .setOutput(getTunnelPort(deviceId)); |
| 237 | |
| 238 | ForwardingObjective fo = DefaultForwardingObjective.builder() |
| 239 | .withSelector(sBuilder.build()) |
| 240 | .withTreatment(tBuilder.build()) |
| 241 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 242 | .withPriority(PNAT_RULE_PRIORITY) |
| 243 | .makeTemporary(PNAT_TIMEOUT) |
| 244 | .fromApp(appId) |
| 245 | .add(); |
| 246 | |
| 247 | flowObjectiveService.forward(inboundPacket.receivedFrom().deviceId(), fo); |
| 248 | } |
| 249 | |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 250 | private Ip4Address getHostIpfromOpenstackPort(OpenstackPort openstackPort) { |
| 251 | Device device = getDevicefromOpenstackPort(openstackPort); |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 252 | return config.nodes().get(device.id()); |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 253 | } |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 254 | |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 255 | private Device getDevicefromOpenstackPort(OpenstackPort openstackPort) { |
| 256 | String openstackPortName = PORTNAME_PREFIX_VM + openstackPort.id().substring(0, 11); |
| 257 | Device device = StreamSupport.stream(deviceService.getDevices().spliterator(), false) |
| 258 | .filter(d -> findPortinDevice(d, openstackPortName)) |
Kyuhwi Choi | 5e65e2c | 2016-04-01 11:48:15 +0900 | [diff] [blame^] | 259 | .iterator() |
| 260 | .next(); |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 261 | checkNotNull(device, DEVICENOTNULL); |
| 262 | return device; |
| 263 | } |
| 264 | |
| 265 | private boolean findPortinDevice(Device d, String openstackPortName) { |
| 266 | Port port = deviceService.getPorts(d.id()) |
| 267 | .stream() |
| 268 | .filter(p -> p.isEnabled() && p.annotations().value(PORTNAME).equals(openstackPortName)) |
| 269 | .findAny() |
| 270 | .orElse(null); |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 271 | return port != null; |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /** |
Kyuhwi Choi | 5e65e2c | 2016-04-01 11:48:15 +0900 | [diff] [blame^] | 275 | * Builds Nicira extension for tagging remoteIp of vxlan. |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 276 | * |
| 277 | * @param id Device Id of vxlan source device |
| 278 | * @param hostIp Remote Ip of vxlan destination device |
| 279 | * @return NiciraExtension Treatment |
| 280 | */ |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 281 | public ExtensionTreatment buildNiciraExtenstion(DeviceId id, Ip4Address hostIp) { |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 282 | Driver driver = driverService.getDriver(id); |
| 283 | DriverHandler driverHandler = new DefaultDriverHandler(new DefaultDriverData(driver, id)); |
| 284 | ExtensionTreatmentResolver resolver = driverHandler.behaviour(ExtensionTreatmentResolver.class); |
| 285 | |
| 286 | ExtensionTreatment extensionInstruction = |
| 287 | resolver.getExtensionInstruction( |
| 288 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type()); |
| 289 | |
| 290 | try { |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 291 | extensionInstruction.setPropertyValue(TUNNEL_DESTINATION, hostIp); |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 292 | } catch (ExtensionPropertyException e) { |
| 293 | log.error("Error setting Nicira extension setting {}", e); |
| 294 | } |
| 295 | |
| 296 | return extensionInstruction; |
| 297 | } |
| 298 | |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 299 | /** |
| 300 | * Returns port number of vxlan tunnel. |
| 301 | * |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 302 | * @param deviceId Target Device Id |
| 303 | * @return PortNumber |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 304 | */ |
| 305 | public PortNumber getTunnelPort(DeviceId deviceId) { |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 306 | Port port = deviceService.getPorts(deviceId).stream() |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 307 | .filter(p -> p.annotations().value(PORTNAME).equals(PORTNAME_PREFIX_TUNNEL)) |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 308 | .findAny().orElse(null); |
| 309 | |
| 310 | if (port == null) { |
| 311 | log.error("No TunnelPort was created."); |
| 312 | return null; |
| 313 | } |
| 314 | return port.number(); |
| 315 | |
| 316 | } |
| 317 | |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 318 | /** |
| 319 | * Populates flow rules from openstackComputeNode to GatewayNode. |
| 320 | * |
| 321 | * @param vni Target network |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 322 | */ |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 323 | public void populateExternalRules(long vni) { |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 324 | |
| 325 | // 1. computeNode to gateway |
| 326 | populateComputeNodeRules(vni); |
| 327 | // 2. gatewayNode to controller |
| 328 | populateRuleGatewaytoController(vni); |
| 329 | } |
| 330 | |
| 331 | private void populateRuleGatewaytoController(long vni) { |
| 332 | Device gatewayDevice = getGatewayNode(); |
| 333 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 334 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 335 | |
| 336 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) |
| 337 | .matchTunnelId(vni) |
| 338 | .matchEthDst(GATEWAYMAC); |
| 339 | tBuilder.setOutput(PortNumber.CONTROLLER); |
| 340 | |
| 341 | ForwardingObjective fo = DefaultForwardingObjective.builder() |
| 342 | .withSelector(sBuilder.build()) |
| 343 | .withTreatment(tBuilder.build()) |
| 344 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 345 | .withPriority(ROUTING_RULE_PRIORITY) |
| 346 | .fromApp(appId) |
| 347 | .add(); |
| 348 | |
| 349 | flowObjectiveService.forward(gatewayDevice.id(), fo); |
| 350 | } |
| 351 | |
| 352 | private void populateComputeNodeRules(long vni) { |
| 353 | Device gatewayDevice = getGatewayNode(); |
| 354 | |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 355 | StreamSupport.stream(deviceService.getDevices().spliterator(), false) |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 356 | .filter(d -> !checkGatewayNode(d.id())) |
| 357 | .forEach(d -> populateRuleToGateway(d, gatewayDevice, vni)); |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | private void populateRuleToGateway(Device d, Device gatewayDevice, long vni) { |
| 361 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 362 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 363 | |
| 364 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) |
| 365 | .matchTunnelId(vni) |
| 366 | .matchEthDst(GATEWAYMAC); |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 367 | tBuilder.extension(buildNiciraExtenstion(d.id(), config.nodes().get(gatewayDevice.id())), d.id()) |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 368 | .setOutput(getTunnelPort(d.id())); |
| 369 | |
| 370 | ForwardingObjective fo = DefaultForwardingObjective.builder() |
| 371 | .withSelector(sBuilder.build()) |
| 372 | .withTreatment(tBuilder.build()) |
| 373 | .withFlag(ForwardingObjective.Flag.SPECIFIC) |
| 374 | .withPriority(ROUTING_RULE_PRIORITY) |
| 375 | .fromApp(appId) |
| 376 | .add(); |
| 377 | |
| 378 | flowObjectiveService.forward(d.id(), fo); |
| 379 | } |
| 380 | |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 381 | private Device getGatewayNode() { |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 382 | return checkNotNull(deviceService.getDevice(DeviceId.deviceId(config.gatewayBridgeId()))); |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | private boolean checkGatewayNode(DeviceId deviceId) { |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 386 | return deviceId.toString().equals(config.gatewayBridgeId()); |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 387 | } |
| 388 | |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 389 | private long getVni(String netId) { |
| 390 | return Long.parseLong(openstackService.network(netId).segmentId()); |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | /** |
| 394 | * Remove flow rules for external connection. |
| 395 | * |
| 396 | * @param routerInterface Corresponding routerInterface |
| 397 | */ |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 398 | public void removeExternalRules(OpenstackRouterInterface routerInterface) { |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 399 | OpenstackSubnet openstackSubnet = openstackService.subnet(routerInterface.subnetId()); |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 400 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 401 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 402 | .matchTunnelId(getVni(openstackSubnet.networkId())) |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 403 | .matchEthDst(GATEWAYMAC); |
| 404 | |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 405 | StreamSupport.stream(deviceService.getDevices().spliterator(), false) |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 406 | .forEach(d -> { |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 407 | ForwardingObjective.Flag flag = checkGatewayNode(d.id()) ? |
Kyuhwi Choi | 5e65e2c | 2016-04-01 11:48:15 +0900 | [diff] [blame^] | 408 | ForwardingObjective.Flag.VERSATILE : |
| 409 | ForwardingObjective.Flag.SPECIFIC; |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 410 | removeRule(d.id(), sBuilder, flag, ROUTING_RULE_PRIORITY); |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 411 | }); |
| 412 | |
| 413 | } |
| 414 | |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 415 | private void removeRule(DeviceId id, TrafficSelector.Builder sBuilder, |
| 416 | ForwardingObjective.Flag flag, int priority) { |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 417 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 418 | |
| 419 | ForwardingObjective fo = DefaultForwardingObjective.builder() |
| 420 | .withSelector(sBuilder.build()) |
| 421 | .withTreatment(tBuilder.build()) |
| 422 | .withFlag(flag) |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 423 | .withPriority(priority) |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 424 | .fromApp(appId) |
| 425 | .remove(); |
| 426 | |
| 427 | flowObjectiveService.forward(id, fo); |
| 428 | } |
| 429 | |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 430 | /** |
| 431 | * Populates flow rules for floatingIp configuration. |
| 432 | * |
| 433 | * @param floatingIP Corresponding floating ip information |
| 434 | */ |
| 435 | public void populateFloatingIpRules(OpenstackFloatingIP floatingIP) { |
| 436 | OpenstackPort port = openstackService.port(floatingIP.portId()); |
| 437 | //1. incoming rules |
| 438 | populateFloatingIpIncomingRules(floatingIP, port); |
| 439 | //2. outgoing rules |
| 440 | populateFloatingIpOutgoingRules(floatingIP, port); |
| 441 | } |
| 442 | |
| 443 | private void populateFloatingIpIncomingRules(OpenstackFloatingIP floatingIP, OpenstackPort port) { |
| 444 | DeviceId portDeviceId = getDevicefromOpenstackPort(port).id(); |
| 445 | Device gatewayNode = getGatewayNode(); |
| 446 | Device portNode = deviceService.getDevice(portDeviceId); |
| 447 | |
| 448 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 449 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 450 | |
| 451 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 452 | .matchIPDst(IpPrefix.valueOf(floatingIP.floatingIpAddress(), PREFIX_LENGTH)); |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 453 | |
| 454 | tBuilder.setEthSrc(MacAddress.valueOf(config.gatewayExternalInterfaceMac())) |
| 455 | .setEthDst(port.macAddress()) |
| 456 | .setIpDst(floatingIP.fixedIpAddress()) |
| 457 | .setTunnelId(getVni(port.networkId())) |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 458 | .extension(buildNiciraExtenstion(gatewayNode.id(), |
| 459 | config.nodes().get(portNode.id())), gatewayNode.id()) |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 460 | .setOutput(getTunnelPort(gatewayNode.id())); |
| 461 | |
| 462 | ForwardingObjective fo = DefaultForwardingObjective.builder() |
| 463 | .withSelector(sBuilder.build()) |
| 464 | .withTreatment(tBuilder.build()) |
| 465 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 466 | .withPriority(FLOATING_RULE_PRIORITY) |
| 467 | .fromApp(appId) |
| 468 | .add(); |
| 469 | |
| 470 | flowObjectiveService.forward(getGatewayNode().id(), fo); |
| 471 | |
| 472 | } |
| 473 | |
| 474 | private void populateFloatingIpOutgoingRules(OpenstackFloatingIP floatingIP, OpenstackPort port) { |
| 475 | Port outputPort = checkNotNull(getPortOfExternalInterface(), PORTNOTNULL); |
| 476 | |
| 477 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 478 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 479 | |
| 480 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) |
| 481 | .matchTunnelId(getVni(port.networkId())) |
| 482 | .matchIPSrc(IpPrefix.valueOf(floatingIP.fixedIpAddress(), 32)); |
| 483 | |
| 484 | tBuilder.setIpSrc(floatingIP.floatingIpAddress()) |
| 485 | .setEthSrc(MacAddress.valueOf(config.gatewayExternalInterfaceMac())) |
| 486 | .setEthDst(MacAddress.valueOf(config.physicalRouterMac())) |
| 487 | .setOutput(outputPort.number()); |
| 488 | |
| 489 | ForwardingObjective fo = DefaultForwardingObjective.builder() |
| 490 | .withSelector(sBuilder.build()) |
| 491 | .withTreatment(tBuilder.build()) |
| 492 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 493 | .withPriority(FLOATING_RULE_PRIORITY) |
| 494 | .fromApp(appId) |
| 495 | .add(); |
| 496 | |
| 497 | flowObjectiveService.forward(getGatewayNode().id(), fo); |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * Removes flow rules for floating ip configuration. |
| 502 | * |
| 503 | * @param floatingIP Corresponding floating ip information |
Ray Milkey | d4334db | 2016-04-05 17:39:44 -0700 | [diff] [blame] | 504 | * @param portInfo stored information about deleted vm |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 505 | */ |
| 506 | public void removeFloatingIpRules(OpenstackFloatingIP floatingIP, OpenstackPortInfo portInfo) { |
| 507 | TrafficSelector.Builder sOutgoingBuilder = DefaultTrafficSelector.builder(); |
| 508 | TrafficSelector.Builder sIncomingBuilder = DefaultTrafficSelector.builder(); |
| 509 | |
| 510 | sOutgoingBuilder.matchEthType(Ethernet.TYPE_IPV4) |
| 511 | .matchTunnelId(portInfo.vni()) |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 512 | .matchIPSrc(IpPrefix.valueOf(portInfo.ip(), PREFIX_LENGTH)); |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 513 | |
| 514 | sIncomingBuilder.matchEthType(Ethernet.TYPE_IPV4) |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 515 | .matchIPDst(IpPrefix.valueOf(floatingIP.floatingIpAddress(), PREFIX_LENGTH)); |
Kyuhwi Choi | ee9e371 | 2016-02-22 22:49:36 +0900 | [diff] [blame] | 516 | |
| 517 | removeRule(getGatewayNode().id(), sOutgoingBuilder, ForwardingObjective.Flag.VERSATILE, FLOATING_RULE_PRIORITY); |
| 518 | removeRule(getGatewayNode().id(), sIncomingBuilder, ForwardingObjective.Flag.VERSATILE, FLOATING_RULE_PRIORITY); |
| 519 | } |
| 520 | |
Kyuhwi Choi | 5e65e2c | 2016-04-01 11:48:15 +0900 | [diff] [blame^] | 521 | /** |
| 522 | * Populates L3 rules for east to west traffic. |
| 523 | * |
| 524 | * @param p target VM |
| 525 | * @param targetList target openstackRouterInterfaces |
| 526 | */ |
| 527 | public void populateL3Rules(OpenstackPort p, List<OpenstackRouterInterface> targetList) { |
| 528 | Device device = getDevicefromOpenstackPort(p); |
| 529 | Port port = getPortFromOpenstackPort(device, p); |
| 530 | Ip4Address vmIp = (Ip4Address) p.fixedIps().values().iterator().next(); |
| 531 | |
| 532 | if (port == null) { |
| 533 | return; |
| 534 | } |
| 535 | |
| 536 | targetList.forEach(routerInterface -> { |
| 537 | OpenstackPort openstackPort = openstackService.port(routerInterface.portId()); |
| 538 | long vni = getVni(openstackPort.networkId()); |
| 539 | |
| 540 | if (vmIp == null) { |
| 541 | return; |
| 542 | } |
| 543 | |
| 544 | populateL3RulestoSameNode(vmIp, p, port, device, vni); |
| 545 | |
| 546 | deviceService.getAvailableDevices().forEach(d -> { |
| 547 | if (!d.equals(device) && !d.equals(getGatewayNode())) { |
| 548 | populateL3RulestoDifferentNode(vmIp, vni, d.id(), getHostIpfromOpenstackPort(p)); |
| 549 | } |
| 550 | }); |
| 551 | |
| 552 | }); |
| 553 | } |
| 554 | |
| 555 | private void populateL3RulestoDifferentNode(Ip4Address vmIp, long vni, DeviceId deviceId, Ip4Address hostIp) { |
| 556 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 557 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 558 | |
| 559 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) |
| 560 | .matchTunnelId(vni) |
| 561 | .matchIPDst(vmIp.toIpPrefix()); |
| 562 | tBuilder.extension(buildNiciraExtenstion(deviceId, hostIp), deviceId) |
| 563 | .setOutput(getTunnelPort(deviceId)); |
| 564 | |
| 565 | ForwardingObjective fo = DefaultForwardingObjective.builder() |
| 566 | .withSelector(sBuilder.build()) |
| 567 | .withTreatment(tBuilder.build()) |
| 568 | .withPriority(ROUTING_RULE_PRIORITY) |
| 569 | .withFlag(ForwardingObjective.Flag.SPECIFIC) |
| 570 | .fromApp(appId) |
| 571 | .add(); |
| 572 | |
| 573 | flowObjectiveService.forward(deviceId, fo); |
| 574 | } |
| 575 | |
| 576 | private void populateL3RulestoSameNode(Ip4Address vmIp, OpenstackPort p, Port port, Device device, long vni) { |
| 577 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 578 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 579 | |
| 580 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) |
| 581 | .matchIPDst(vmIp.toIpPrefix()) |
| 582 | .matchTunnelId(vni); |
| 583 | |
| 584 | tBuilder.setEthDst(p.macAddress()) |
| 585 | .setOutput(port.number()); |
| 586 | |
| 587 | ForwardingObjective fo = DefaultForwardingObjective.builder() |
| 588 | .withSelector(sBuilder.build()) |
| 589 | .withTreatment(tBuilder.build()) |
| 590 | .withPriority(ROUTING_RULE_PRIORITY) |
| 591 | .withFlag(ForwardingObjective.Flag.SPECIFIC) |
| 592 | .fromApp(appId) |
| 593 | .add(); |
| 594 | |
| 595 | flowObjectiveService.forward(device.id(), fo); |
| 596 | } |
| 597 | |
| 598 | private Port getPortFromOpenstackPort(Device device, OpenstackPort p) { |
| 599 | String openstackPortName = PORTNAME_PREFIX_VM + p.id().substring(0, 11); |
| 600 | return deviceService.getPorts(device.id()) |
| 601 | .stream() |
| 602 | .filter(pt -> pt.annotations().value(PORTNAME).equals(openstackPortName)) |
| 603 | .findAny() |
| 604 | .orElse(null); |
| 605 | } |
| 606 | |
| 607 | /** |
| 608 | * Removes L3 rules for routerInterface events. |
| 609 | * |
| 610 | * @param vmIp Corresponding Vm ip |
| 611 | * @param routerInterfaces Corresponding routerInterfaces |
| 612 | */ |
| 613 | public void removeL3Rules(Ip4Address vmIp, List<OpenstackRouterInterface> routerInterfaces) { |
| 614 | if (vmIp == null) { |
| 615 | return; |
| 616 | } |
| 617 | |
| 618 | OpenstackRoutingService routingService = getService(OpenstackRoutingService.class); |
| 619 | |
| 620 | deviceService.getAvailableDevices().forEach(d -> { |
| 621 | if (!d.equals(getGatewayNode())) { |
| 622 | routerInterfaces.forEach(routerInterface -> { |
| 623 | String networkId = routingService.networkIdForRouterInterface(routerInterface.portId()); |
| 624 | long vni = getVni(networkId); |
| 625 | |
| 626 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 627 | |
| 628 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) |
| 629 | .matchIPDst(vmIp.toIpPrefix()) |
| 630 | .matchTunnelId(vni); |
| 631 | |
| 632 | removeRule(d.id(), sBuilder, ForwardingObjective.Flag.SPECIFIC, ROUTING_RULE_PRIORITY); |
| 633 | }); |
| 634 | } |
| 635 | }); |
| 636 | } |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 637 | } |