Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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 | */ |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 16 | package org.opencord.cordvtn.impl; |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 17 | |
| 18 | import org.apache.felix.scr.annotations.Activate; |
| 19 | import org.apache.felix.scr.annotations.Component; |
| 20 | import org.apache.felix.scr.annotations.Deactivate; |
| 21 | import org.apache.felix.scr.annotations.Reference; |
| 22 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 23 | import org.apache.felix.scr.annotations.Service; |
| 24 | import org.onlab.packet.Ethernet; |
| 25 | import org.onlab.packet.IPv4; |
| 26 | import org.onlab.packet.Ip4Address; |
| 27 | import org.onlab.packet.IpAddress; |
| 28 | import org.onlab.packet.TpPort; |
| 29 | import org.onlab.packet.VlanId; |
Hyunsun Moon | 315b9a6 | 2016-06-23 14:48:04 -0700 | [diff] [blame^] | 30 | import org.onlab.util.ItemNotFoundException; |
Hyunsun Moon | 5401aaa | 2016-06-12 17:40:34 -0700 | [diff] [blame] | 31 | import org.opencord.cordvtn.api.Constants; |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 32 | import org.opencord.cordvtn.api.CordVtnNode; |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 33 | import org.onosproject.core.ApplicationId; |
| 34 | import org.onosproject.core.CoreService; |
| 35 | import org.onosproject.net.Device; |
| 36 | import org.onosproject.net.DeviceId; |
| 37 | import org.onosproject.net.PortNumber; |
| 38 | import org.onosproject.net.behaviour.ExtensionTreatmentResolver; |
| 39 | import org.onosproject.net.device.DeviceService; |
| 40 | import org.onosproject.net.flow.DefaultFlowRule; |
| 41 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 42 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 43 | import org.onosproject.net.flow.FlowRule; |
| 44 | import org.onosproject.net.flow.FlowRuleOperations; |
| 45 | import org.onosproject.net.flow.FlowRuleOperationsContext; |
| 46 | import org.onosproject.net.flow.FlowRuleService; |
| 47 | import org.onosproject.net.flow.TrafficSelector; |
| 48 | import org.onosproject.net.flow.TrafficTreatment; |
| 49 | import org.onosproject.net.flow.instructions.ExtensionPropertyException; |
| 50 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
| 51 | import org.slf4j.Logger; |
| 52 | |
| 53 | import static com.google.common.base.Preconditions.checkNotNull; |
| 54 | import static org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST; |
| 55 | import static org.slf4j.LoggerFactory.getLogger; |
| 56 | |
| 57 | /** |
| 58 | * Provides CORD VTN pipeline. |
| 59 | */ |
| 60 | @Component(immediate = true) |
| 61 | @Service(value = CordVtnPipeline.class) |
| 62 | public final class CordVtnPipeline { |
| 63 | |
| 64 | protected final Logger log = getLogger(getClass()); |
| 65 | |
| 66 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 67 | protected CoreService coreService; |
| 68 | |
| 69 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 70 | protected FlowRuleService flowRuleService; |
| 71 | |
| 72 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 73 | protected DeviceService deviceService; |
| 74 | |
| 75 | // tables |
| 76 | public static final int TABLE_ZERO = 0; |
| 77 | public static final int TABLE_IN_PORT = 1; |
Hyunsun Moon | fb41794 | 2016-06-23 14:48:20 -0700 | [diff] [blame] | 78 | public static final int TABLE_ACCESS_TYPE = 2; |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 79 | public static final int TABLE_IN_SERVICE = 3; |
Hyunsun Moon | fb41794 | 2016-06-23 14:48:20 -0700 | [diff] [blame] | 80 | public static final int TABLE_DST_IP = 4; |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 81 | public static final int TABLE_TUNNEL_IN = 5; |
| 82 | public static final int TABLE_VLAN = 6; |
| 83 | |
| 84 | // priorities |
| 85 | public static final int PRIORITY_MANAGEMENT = 55000; |
| 86 | public static final int PRIORITY_HIGH = 50000; |
| 87 | public static final int PRIORITY_DEFAULT = 5000; |
| 88 | public static final int PRIORITY_LOW = 4000; |
| 89 | public static final int PRIORITY_ZERO = 0; |
| 90 | |
| 91 | public static final int VXLAN_UDP_PORT = 4789; |
| 92 | public static final VlanId VLAN_WAN = VlanId.vlanId((short) 500); |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 93 | |
| 94 | private ApplicationId appId; |
| 95 | |
| 96 | @Activate |
| 97 | protected void activate() { |
Hyunsun Moon | 5401aaa | 2016-06-12 17:40:34 -0700 | [diff] [blame] | 98 | appId = coreService.registerApplication(Constants.CORDVTN_APP_ID); |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 99 | log.info("Started"); |
| 100 | } |
| 101 | |
| 102 | @Deactivate |
| 103 | protected void deactivate() { |
| 104 | log.info("Stopped"); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Flush flows installed by this application. |
| 109 | */ |
| 110 | public void flushRules() { |
| 111 | flowRuleService.getFlowRulesById(appId).forEach(flowRule -> processFlowRule(false, flowRule)); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Installs table miss rule to a give device. |
| 116 | * |
| 117 | * @param node cordvtn node |
Hyunsun Moon | 315b9a6 | 2016-06-23 14:48:04 -0700 | [diff] [blame^] | 118 | * @param dataPort data plane port number |
| 119 | * @param tunnelPort tunnel port number |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 120 | */ |
Hyunsun Moon | 315b9a6 | 2016-06-23 14:48:04 -0700 | [diff] [blame^] | 121 | public void initPipeline(CordVtnNode node, PortNumber dataPort, PortNumber tunnelPort) { |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 122 | checkNotNull(node); |
| 123 | |
Hyunsun Moon | 315b9a6 | 2016-06-23 14:48:04 -0700 | [diff] [blame^] | 124 | processTableZero(node.integrationBridgeId(), dataPort, node.dataIp().ip()); |
| 125 | processInPortTable(node.integrationBridgeId(), tunnelPort, dataPort); |
| 126 | processAccessTypeTable(node.integrationBridgeId(), dataPort); |
| 127 | processVlanTable(node.integrationBridgeId(), dataPort); |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Hyunsun Moon | 315b9a6 | 2016-06-23 14:48:04 -0700 | [diff] [blame^] | 130 | private void processTableZero(DeviceId deviceId, PortNumber dataPort, IpAddress dataIp) { |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 131 | // take vxlan packet out onto the physical port |
| 132 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| 133 | .matchInPort(PortNumber.LOCAL) |
| 134 | .build(); |
| 135 | |
| 136 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
Hyunsun Moon | 3ef5249 | 2016-06-15 14:56:31 -0700 | [diff] [blame] | 137 | .setOutput(dataPort) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 138 | .build(); |
| 139 | |
| 140 | FlowRule flowRule = DefaultFlowRule.builder() |
| 141 | .fromApp(appId) |
| 142 | .withSelector(selector) |
| 143 | .withTreatment(treatment) |
| 144 | .withPriority(PRIORITY_HIGH) |
| 145 | .forDevice(deviceId) |
| 146 | .forTable(TABLE_ZERO) |
| 147 | .makePermanent() |
| 148 | .build(); |
| 149 | |
| 150 | processFlowRule(true, flowRule); |
| 151 | |
| 152 | // take a vxlan encap'd packet through the Linux stack |
| 153 | selector = DefaultTrafficSelector.builder() |
Hyunsun Moon | 3ef5249 | 2016-06-15 14:56:31 -0700 | [diff] [blame] | 154 | .matchInPort(dataPort) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 155 | .matchEthType(Ethernet.TYPE_IPV4) |
| 156 | .matchIPProtocol(IPv4.PROTOCOL_UDP) |
| 157 | .matchUdpDst(TpPort.tpPort(VXLAN_UDP_PORT)) |
| 158 | .build(); |
| 159 | |
| 160 | treatment = DefaultTrafficTreatment.builder() |
| 161 | .setOutput(PortNumber.LOCAL) |
| 162 | .build(); |
| 163 | |
| 164 | flowRule = DefaultFlowRule.builder() |
| 165 | .fromApp(appId) |
| 166 | .withSelector(selector) |
| 167 | .withTreatment(treatment) |
| 168 | .withPriority(PRIORITY_HIGH) |
| 169 | .forDevice(deviceId) |
| 170 | .forTable(TABLE_ZERO) |
| 171 | .makePermanent() |
| 172 | .build(); |
| 173 | |
| 174 | processFlowRule(true, flowRule); |
| 175 | |
| 176 | // take a packet to the data plane ip through Linux stack |
| 177 | selector = DefaultTrafficSelector.builder() |
Hyunsun Moon | 3ef5249 | 2016-06-15 14:56:31 -0700 | [diff] [blame] | 178 | .matchInPort(dataPort) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 179 | .matchEthType(Ethernet.TYPE_IPV4) |
Hyunsun Moon | 3ef5249 | 2016-06-15 14:56:31 -0700 | [diff] [blame] | 180 | .matchIPDst(dataIp.toIpPrefix()) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 181 | .build(); |
| 182 | |
| 183 | treatment = DefaultTrafficTreatment.builder() |
| 184 | .setOutput(PortNumber.LOCAL) |
| 185 | .build(); |
| 186 | |
| 187 | flowRule = DefaultFlowRule.builder() |
| 188 | .fromApp(appId) |
| 189 | .withSelector(selector) |
| 190 | .withTreatment(treatment) |
| 191 | .withPriority(PRIORITY_HIGH) |
| 192 | .forDevice(deviceId) |
| 193 | .forTable(TABLE_ZERO) |
| 194 | .makePermanent() |
| 195 | .build(); |
| 196 | |
| 197 | processFlowRule(true, flowRule); |
| 198 | |
| 199 | // take an arp packet from physical through Linux stack |
| 200 | selector = DefaultTrafficSelector.builder() |
Hyunsun Moon | 3ef5249 | 2016-06-15 14:56:31 -0700 | [diff] [blame] | 201 | .matchInPort(dataPort) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 202 | .matchEthType(Ethernet.TYPE_ARP) |
Hyunsun Moon | 3ef5249 | 2016-06-15 14:56:31 -0700 | [diff] [blame] | 203 | .matchArpTpa(dataIp.getIp4Address()) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 204 | .build(); |
| 205 | |
| 206 | treatment = DefaultTrafficTreatment.builder() |
| 207 | .setOutput(PortNumber.LOCAL) |
| 208 | .build(); |
| 209 | |
| 210 | flowRule = DefaultFlowRule.builder() |
| 211 | .fromApp(appId) |
| 212 | .withSelector(selector) |
| 213 | .withTreatment(treatment) |
| 214 | .withPriority(PRIORITY_HIGH) |
| 215 | .forDevice(deviceId) |
| 216 | .forTable(TABLE_ZERO) |
| 217 | .makePermanent() |
| 218 | .build(); |
| 219 | |
| 220 | processFlowRule(true, flowRule); |
| 221 | |
Hyunsun Moon | 315b9a6 | 2016-06-23 14:48:04 -0700 | [diff] [blame^] | 222 | // take all else to the next table |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 223 | selector = DefaultTrafficSelector.builder() |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 224 | .build(); |
| 225 | |
| 226 | treatment = DefaultTrafficTreatment.builder() |
Hyunsun Moon | 315b9a6 | 2016-06-23 14:48:04 -0700 | [diff] [blame^] | 227 | .transition(TABLE_IN_PORT) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 228 | .build(); |
| 229 | |
| 230 | flowRule = DefaultFlowRule.builder() |
| 231 | .fromApp(appId) |
| 232 | .withSelector(selector) |
| 233 | .withTreatment(treatment) |
Hyunsun Moon | 315b9a6 | 2016-06-23 14:48:04 -0700 | [diff] [blame^] | 234 | .withPriority(PRIORITY_ZERO) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 235 | .forDevice(deviceId) |
Hyunsun Moon | 315b9a6 | 2016-06-23 14:48:04 -0700 | [diff] [blame^] | 236 | .forTable(TABLE_ZERO) |
Hyunsun Moon | acbc8ef | 2016-06-21 17:58:45 -0700 | [diff] [blame] | 237 | .makePermanent() |
| 238 | .build(); |
| 239 | |
| 240 | processFlowRule(true, flowRule); |
| 241 | |
Hyunsun Moon | 315b9a6 | 2016-06-23 14:48:04 -0700 | [diff] [blame^] | 242 | // take all vlan tagged packet to the VLAN table |
Hyunsun Moon | acbc8ef | 2016-06-21 17:58:45 -0700 | [diff] [blame] | 243 | selector = DefaultTrafficSelector.builder() |
Hyunsun Moon | 315b9a6 | 2016-06-23 14:48:04 -0700 | [diff] [blame^] | 244 | .matchVlanId(VlanId.ANY) |
Hyunsun Moon | acbc8ef | 2016-06-21 17:58:45 -0700 | [diff] [blame] | 245 | .build(); |
| 246 | |
| 247 | treatment = DefaultTrafficTreatment.builder() |
Hyunsun Moon | 315b9a6 | 2016-06-23 14:48:04 -0700 | [diff] [blame^] | 248 | .transition(TABLE_VLAN) |
Hyunsun Moon | acbc8ef | 2016-06-21 17:58:45 -0700 | [diff] [blame] | 249 | .build(); |
| 250 | |
| 251 | flowRule = DefaultFlowRule.builder() |
| 252 | .fromApp(appId) |
| 253 | .withSelector(selector) |
| 254 | .withTreatment(treatment) |
Hyunsun Moon | 315b9a6 | 2016-06-23 14:48:04 -0700 | [diff] [blame^] | 255 | .withPriority(PRIORITY_MANAGEMENT) |
Hyunsun Moon | acbc8ef | 2016-06-21 17:58:45 -0700 | [diff] [blame] | 256 | .forDevice(deviceId) |
Hyunsun Moon | 315b9a6 | 2016-06-23 14:48:04 -0700 | [diff] [blame^] | 257 | .forTable(TABLE_ZERO) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 258 | .makePermanent() |
| 259 | .build(); |
| 260 | |
| 261 | processFlowRule(true, flowRule); |
| 262 | } |
| 263 | |
Hyunsun Moon | 315b9a6 | 2016-06-23 14:48:04 -0700 | [diff] [blame^] | 264 | private void processInPortTable(DeviceId deviceId, PortNumber tunnelPort, PortNumber dataPort) { |
| 265 | checkNotNull(tunnelPort); |
| 266 | |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 267 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| 268 | .matchInPort(tunnelPort) |
| 269 | .build(); |
| 270 | |
| 271 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 272 | .transition(TABLE_TUNNEL_IN) |
| 273 | .build(); |
| 274 | |
| 275 | FlowRule flowRule = DefaultFlowRule.builder() |
| 276 | .fromApp(appId) |
| 277 | .withSelector(selector) |
| 278 | .withTreatment(treatment) |
| 279 | .withPriority(PRIORITY_DEFAULT) |
| 280 | .forDevice(deviceId) |
| 281 | .forTable(TABLE_IN_PORT) |
| 282 | .makePermanent() |
| 283 | .build(); |
| 284 | |
| 285 | processFlowRule(true, flowRule); |
| 286 | |
| 287 | selector = DefaultTrafficSelector.builder() |
Hyunsun Moon | 3ef5249 | 2016-06-15 14:56:31 -0700 | [diff] [blame] | 288 | .matchInPort(dataPort) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 289 | .build(); |
| 290 | |
| 291 | treatment = DefaultTrafficTreatment.builder() |
Hyunsun Moon | fb41794 | 2016-06-23 14:48:20 -0700 | [diff] [blame] | 292 | .transition(TABLE_DST_IP) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 293 | .build(); |
| 294 | |
| 295 | flowRule = DefaultFlowRule.builder() |
| 296 | .fromApp(appId) |
| 297 | .withSelector(selector) |
| 298 | .withTreatment(treatment) |
| 299 | .withPriority(PRIORITY_DEFAULT) |
| 300 | .forDevice(deviceId) |
| 301 | .forTable(TABLE_IN_PORT) |
| 302 | .makePermanent() |
| 303 | .build(); |
| 304 | |
| 305 | processFlowRule(true, flowRule); |
| 306 | } |
| 307 | |
Hyunsun Moon | 3ef5249 | 2016-06-15 14:56:31 -0700 | [diff] [blame] | 308 | private void processAccessTypeTable(DeviceId deviceId, PortNumber dataPort) { |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 309 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| 310 | .build(); |
| 311 | |
| 312 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
Hyunsun Moon | 3ef5249 | 2016-06-15 14:56:31 -0700 | [diff] [blame] | 313 | .setOutput(dataPort) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 314 | .build(); |
| 315 | |
| 316 | FlowRule flowRule = DefaultFlowRule.builder() |
| 317 | .fromApp(appId) |
| 318 | .withSelector(selector) |
| 319 | .withTreatment(treatment) |
| 320 | .withPriority(PRIORITY_ZERO) |
| 321 | .forDevice(deviceId) |
Hyunsun Moon | fb41794 | 2016-06-23 14:48:20 -0700 | [diff] [blame] | 322 | .forTable(TABLE_ACCESS_TYPE) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 323 | .makePermanent() |
| 324 | .build(); |
| 325 | |
| 326 | processFlowRule(true, flowRule); |
| 327 | } |
| 328 | |
Hyunsun Moon | 3ef5249 | 2016-06-15 14:56:31 -0700 | [diff] [blame] | 329 | private void processVlanTable(DeviceId deviceId, PortNumber dataPort) { |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 330 | // for traffic going out to WAN, strip vid 500 and take through data plane interface |
| 331 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| 332 | .matchVlanId(VLAN_WAN) |
| 333 | .build(); |
| 334 | |
| 335 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 336 | .popVlan() |
Hyunsun Moon | 3ef5249 | 2016-06-15 14:56:31 -0700 | [diff] [blame] | 337 | .setOutput(dataPort) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 338 | .build(); |
| 339 | |
| 340 | FlowRule flowRule = DefaultFlowRule.builder() |
| 341 | .fromApp(appId) |
| 342 | .withSelector(selector) |
| 343 | .withTreatment(treatment) |
| 344 | .withPriority(PRIORITY_DEFAULT) |
| 345 | .forDevice(deviceId) |
| 346 | .forTable(TABLE_VLAN) |
| 347 | .makePermanent() |
| 348 | .build(); |
| 349 | |
| 350 | processFlowRule(true, flowRule); |
| 351 | |
| 352 | selector = DefaultTrafficSelector.builder() |
| 353 | .matchVlanId(VLAN_WAN) |
| 354 | .matchEthType(Ethernet.TYPE_ARP) |
| 355 | .build(); |
| 356 | |
| 357 | treatment = DefaultTrafficTreatment.builder() |
| 358 | .setOutput(PortNumber.CONTROLLER) |
| 359 | .build(); |
| 360 | |
| 361 | flowRule = DefaultFlowRule.builder() |
| 362 | .fromApp(appId) |
| 363 | .withSelector(selector) |
| 364 | .withTreatment(treatment) |
| 365 | .withPriority(PRIORITY_HIGH) |
| 366 | .forDevice(deviceId) |
| 367 | .forTable(TABLE_VLAN) |
| 368 | .makePermanent() |
| 369 | .build(); |
| 370 | |
| 371 | processFlowRule(true, flowRule); |
| 372 | } |
| 373 | |
| 374 | public void processFlowRule(boolean install, FlowRule rule) { |
| 375 | FlowRuleOperations.Builder oBuilder = FlowRuleOperations.builder(); |
| 376 | oBuilder = install ? oBuilder.add(rule) : oBuilder.remove(rule); |
| 377 | |
| 378 | flowRuleService.apply(oBuilder.build(new FlowRuleOperationsContext() { |
| 379 | @Override |
| 380 | public void onError(FlowRuleOperations ops) { |
| 381 | log.error(String.format("Failed %s, %s", ops.toString(), rule.toString())); |
| 382 | } |
| 383 | })); |
| 384 | } |
| 385 | |
| 386 | public ExtensionTreatment tunnelDstTreatment(DeviceId deviceId, Ip4Address remoteIp) { |
Hyunsun Moon | acbc8ef | 2016-06-21 17:58:45 -0700 | [diff] [blame] | 387 | try { |
Hyunsun Moon | 315b9a6 | 2016-06-23 14:48:04 -0700 | [diff] [blame^] | 388 | Device device = deviceService.getDevice(deviceId); |
| 389 | if (!device.is(ExtensionTreatmentResolver.class)) { |
| 390 | log.error("The extension treatment is not supported"); |
| 391 | return null; |
| 392 | |
| 393 | } |
| 394 | |
| 395 | ExtensionTreatmentResolver resolver = device.as(ExtensionTreatmentResolver.class); |
| 396 | ExtensionTreatment treatment = |
| 397 | resolver.getExtensionInstruction(NICIRA_SET_TUNNEL_DST.type()); |
| 398 | treatment.setPropertyValue("tunnelDst", remoteIp); |
Hyunsun Moon | acbc8ef | 2016-06-21 17:58:45 -0700 | [diff] [blame] | 399 | return treatment; |
Hyunsun Moon | 315b9a6 | 2016-06-23 14:48:04 -0700 | [diff] [blame^] | 400 | } catch (ItemNotFoundException | UnsupportedOperationException | |
| 401 | ExtensionPropertyException e) { |
| 402 | log.error("Failed to get extension instruction {}", deviceId); |
Hyunsun Moon | acbc8ef | 2016-06-21 17:58:45 -0700 | [diff] [blame] | 403 | return null; |
| 404 | } |
| 405 | } |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 406 | } |