Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame^] | 2 | * Copyright 2015-present Open Networking Laboratory |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [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.sfc.manager.impl; |
| 17 | |
Phaneendra Manda | 5c8257b | 2016-02-03 22:07:38 +0530 | [diff] [blame] | 18 | import static org.slf4j.LoggerFactory.getLogger; |
| 19 | |
Phaneendra Manda | b355503 | 2016-02-08 11:41:53 +0530 | [diff] [blame] | 20 | import java.util.Collection; |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 21 | import java.util.Iterator; |
| 22 | import java.util.List; |
| 23 | import java.util.Optional; |
Phaneendra Manda | b355503 | 2016-02-08 11:41:53 +0530 | [diff] [blame] | 24 | import java.util.Set; |
Phaneendra Manda | 5c8257b | 2016-02-03 22:07:38 +0530 | [diff] [blame] | 25 | |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 26 | import org.apache.felix.scr.annotations.Activate; |
| 27 | import org.apache.felix.scr.annotations.Component; |
| 28 | import org.apache.felix.scr.annotations.Deactivate; |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 29 | import org.apache.felix.scr.annotations.Reference; |
| 30 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 31 | import org.apache.felix.scr.annotations.Service; |
Phaneendra Manda | 5c8257b | 2016-02-03 22:07:38 +0530 | [diff] [blame] | 32 | import org.onlab.packet.Ethernet; |
| 33 | import org.onlab.packet.IPv4; |
Phaneendra Manda | 5c8257b | 2016-02-03 22:07:38 +0530 | [diff] [blame] | 34 | import org.onlab.packet.IpAddress; |
| 35 | import org.onlab.packet.MacAddress; |
Phaneendra Manda | b355503 | 2016-02-08 11:41:53 +0530 | [diff] [blame] | 36 | import org.onlab.packet.TCP; |
| 37 | import org.onlab.packet.UDP; |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 38 | import org.onlab.util.ItemNotFoundException; |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 39 | import org.onlab.util.KryoNamespace; |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 40 | import org.onosproject.core.ApplicationId; |
| 41 | import org.onosproject.core.CoreService; |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 42 | import org.onosproject.core.IdGenerator; |
| 43 | import org.onosproject.net.ConnectPoint; |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 44 | import org.onosproject.net.NshServicePathId; |
Phaneendra Manda | b355503 | 2016-02-08 11:41:53 +0530 | [diff] [blame] | 45 | import org.onosproject.net.PortNumber; |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 46 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 47 | import org.onosproject.net.flow.TrafficTreatment; |
| 48 | import org.onosproject.net.packet.DefaultOutboundPacket; |
| 49 | import org.onosproject.net.packet.OutboundPacket; |
Phaneendra Manda | 5c8257b | 2016-02-03 22:07:38 +0530 | [diff] [blame] | 50 | import org.onosproject.net.packet.PacketContext; |
| 51 | import org.onosproject.net.packet.PacketProcessor; |
| 52 | import org.onosproject.net.packet.PacketService; |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 53 | import org.onosproject.sfc.forwarder.ServiceFunctionForwarderService; |
| 54 | import org.onosproject.sfc.forwarder.impl.ServiceFunctionForwarderImpl; |
| 55 | import org.onosproject.sfc.installer.FlowClassifierInstallerService; |
| 56 | import org.onosproject.sfc.installer.impl.FlowClassifierInstallerImpl; |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 57 | import org.onosproject.sfc.manager.SfcService; |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 58 | import org.onosproject.store.serializers.KryoNamespaces; |
| 59 | import org.onosproject.store.service.DistributedSet; |
| 60 | import org.onosproject.store.service.EventuallyConsistentMap; |
| 61 | import org.onosproject.store.service.Serializer; |
| 62 | import org.onosproject.store.service.StorageService; |
| 63 | import org.onosproject.store.service.WallClockTimestamp; |
Phaneendra Manda | b355503 | 2016-02-08 11:41:53 +0530 | [diff] [blame] | 64 | import org.onosproject.vtnrsc.DefaultFiveTuple; |
| 65 | import org.onosproject.vtnrsc.FiveTuple; |
| 66 | import org.onosproject.vtnrsc.FixedIp; |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 67 | import org.onosproject.vtnrsc.FlowClassifier; |
| 68 | import org.onosproject.vtnrsc.FlowClassifierId; |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 69 | import org.onosproject.vtnrsc.LoadBalanceId; |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 70 | import org.onosproject.vtnrsc.PortChain; |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 71 | import org.onosproject.vtnrsc.PortChainId; |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 72 | import org.onosproject.vtnrsc.PortPair; |
| 73 | import org.onosproject.vtnrsc.PortPairGroup; |
| 74 | import org.onosproject.vtnrsc.PortPairGroupId; |
| 75 | import org.onosproject.vtnrsc.PortPairId; |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 76 | import org.onosproject.vtnrsc.TenantId; |
Phaneendra Manda | b355503 | 2016-02-08 11:41:53 +0530 | [diff] [blame] | 77 | import org.onosproject.vtnrsc.VirtualPort; |
| 78 | import org.onosproject.vtnrsc.VirtualPortId; |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 79 | import org.onosproject.vtnrsc.event.VtnRscEvent; |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 80 | import org.onosproject.vtnrsc.event.VtnRscEventFeedback; |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 81 | import org.onosproject.vtnrsc.event.VtnRscListener; |
Phaneendra Manda | b355503 | 2016-02-08 11:41:53 +0530 | [diff] [blame] | 82 | import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService; |
| 83 | import org.onosproject.vtnrsc.portchain.PortChainService; |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 84 | import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService; |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 85 | import org.onosproject.vtnrsc.service.VtnRscService; |
Phaneendra Manda | b355503 | 2016-02-08 11:41:53 +0530 | [diff] [blame] | 86 | import org.onosproject.vtnrsc.virtualport.VirtualPortService; |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 87 | import org.slf4j.Logger; |
| 88 | |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 89 | import com.google.common.collect.Lists; |
| 90 | |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 91 | /** |
| 92 | * Provides implementation of SFC Service. |
| 93 | */ |
| 94 | @Component(immediate = true) |
| 95 | @Service |
| 96 | public class SfcManager implements SfcService { |
| 97 | |
| 98 | private final Logger log = getLogger(getClass()); |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 99 | |
| 100 | private String nshSpiIdTopic = "nsh-spi-id"; |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 101 | private static final String APP_ID = "org.onosproject.app.vtn"; |
Phaneendra Manda | 5c8257b | 2016-02-03 22:07:38 +0530 | [diff] [blame] | 102 | private static final int SFC_PRIORITY = 1000; |
Phaneendra Manda | b355503 | 2016-02-08 11:41:53 +0530 | [diff] [blame] | 103 | private static final int NULL_PORT = 0; |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 104 | private static final int MAX_NSH_SPI_ID = 0x7FFFF; |
| 105 | private static final int MAX_LOAD_BALANCE_ID = 0x20; |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 106 | |
| 107 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 108 | protected VtnRscService vtnRscService; |
| 109 | |
| 110 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 111 | protected CoreService coreService; |
| 112 | |
Phaneendra Manda | 5c8257b | 2016-02-03 22:07:38 +0530 | [diff] [blame] | 113 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 114 | protected PacketService packetService; |
| 115 | |
Phaneendra Manda | b355503 | 2016-02-08 11:41:53 +0530 | [diff] [blame] | 116 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 117 | protected PortChainService portChainService; |
| 118 | |
| 119 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 120 | protected PortPairGroupService portPairGroupService; |
| 121 | |
| 122 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Phaneendra Manda | b355503 | 2016-02-08 11:41:53 +0530 | [diff] [blame] | 123 | protected FlowClassifierService flowClassifierService; |
| 124 | |
| 125 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 126 | protected VirtualPortService virtualPortService; |
| 127 | |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 128 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 129 | protected StorageService storageService; |
| 130 | |
| 131 | protected SfcPacketProcessor processor = new SfcPacketProcessor(); |
Phaneendra Manda | 5c8257b | 2016-02-03 22:07:38 +0530 | [diff] [blame] | 132 | |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 133 | protected ApplicationId appId; |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 134 | protected ServiceFunctionForwarderService serviceFunctionForwarder; |
| 135 | protected FlowClassifierInstallerService flowClassifierInstaller; |
| 136 | protected IdGenerator nshSpiIdGenerator; |
| 137 | protected EventuallyConsistentMap<PortChainId, Integer> nshSpiPortChainMap; |
| 138 | protected DistributedSet<Integer> nshSpiIdFreeList; |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 139 | |
| 140 | private final VtnRscListener vtnRscListener = new InnerVtnRscListener(); |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 141 | |
| 142 | @Activate |
| 143 | public void activate() { |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 144 | appId = coreService.registerApplication(APP_ID); |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 145 | serviceFunctionForwarder = new ServiceFunctionForwarderImpl(appId); |
| 146 | flowClassifierInstaller = new FlowClassifierInstallerImpl(appId); |
| 147 | nshSpiIdGenerator = coreService.getIdGenerator(nshSpiIdTopic); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 148 | |
| 149 | vtnRscService.addListener(vtnRscListener); |
| 150 | |
| 151 | KryoNamespace.Builder serializer = KryoNamespace.newBuilder() |
| 152 | .register(TenantId.class) |
| 153 | .register(PortPairId.class) |
| 154 | .register(PortPairGroupId.class) |
| 155 | .register(FlowClassifierId.class) |
| 156 | .register(PortChainId.class); |
| 157 | |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 158 | nshSpiPortChainMap = storageService.<PortChainId, Integer>eventuallyConsistentMapBuilder() |
| 159 | .withName("nshSpiPortChainMap") |
| 160 | .withSerializer(serializer) |
| 161 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
| 162 | .build(); |
| 163 | |
| 164 | nshSpiIdFreeList = storageService.<Integer>setBuilder() |
| 165 | .withName("nshSpiIdDeletedList") |
| 166 | .withSerializer(Serializer.using(KryoNamespaces.API)) |
| 167 | .build() |
| 168 | .asDistributedSet(); |
| 169 | |
Phaneendra Manda | 5c8257b | 2016-02-03 22:07:38 +0530 | [diff] [blame] | 170 | packetService.addProcessor(processor, PacketProcessor.director(SFC_PRIORITY)); |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 171 | log.info("Started"); |
| 172 | } |
| 173 | |
| 174 | @Deactivate |
| 175 | public void deactivate() { |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 176 | vtnRscService.removeListener(vtnRscListener); |
Phaneendra Manda | 5c8257b | 2016-02-03 22:07:38 +0530 | [diff] [blame] | 177 | packetService.removeProcessor(processor); |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 178 | log.info("Stopped"); |
| 179 | } |
| 180 | |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 181 | /* |
| 182 | * Handle events. |
| 183 | */ |
| 184 | private class InnerVtnRscListener implements VtnRscListener { |
| 185 | @Override |
| 186 | public void event(VtnRscEvent event) { |
| 187 | |
| 188 | if (VtnRscEvent.Type.PORT_PAIR_PUT == event.type()) { |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 189 | PortPair portPair = ((VtnRscEventFeedback) event.subject()).portPair(); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 190 | onPortPairCreated(portPair); |
| 191 | } else if (VtnRscEvent.Type.PORT_PAIR_DELETE == event.type()) { |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 192 | PortPair portPair = ((VtnRscEventFeedback) event.subject()).portPair(); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 193 | onPortPairDeleted(portPair); |
| 194 | } else if (VtnRscEvent.Type.PORT_PAIR_UPDATE == event.type()) { |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 195 | PortPair portPair = ((VtnRscEventFeedback) event.subject()).portPair(); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 196 | onPortPairDeleted(portPair); |
| 197 | onPortPairCreated(portPair); |
| 198 | } else if (VtnRscEvent.Type.PORT_PAIR_GROUP_PUT == event.type()) { |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 199 | PortPairGroup portPairGroup = ((VtnRscEventFeedback) event.subject()).portPairGroup(); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 200 | onPortPairGroupCreated(portPairGroup); |
| 201 | } else if (VtnRscEvent.Type.PORT_PAIR_GROUP_DELETE == event.type()) { |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 202 | PortPairGroup portPairGroup = ((VtnRscEventFeedback) event.subject()).portPairGroup(); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 203 | onPortPairGroupDeleted(portPairGroup); |
| 204 | } else if (VtnRscEvent.Type.PORT_PAIR_GROUP_UPDATE == event.type()) { |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 205 | PortPairGroup portPairGroup = ((VtnRscEventFeedback) event.subject()).portPairGroup(); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 206 | onPortPairGroupDeleted(portPairGroup); |
| 207 | onPortPairGroupCreated(portPairGroup); |
| 208 | } else if (VtnRscEvent.Type.FLOW_CLASSIFIER_PUT == event.type()) { |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 209 | FlowClassifier flowClassifier = ((VtnRscEventFeedback) event.subject()).flowClassifier(); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 210 | onFlowClassifierCreated(flowClassifier); |
| 211 | } else if (VtnRscEvent.Type.FLOW_CLASSIFIER_DELETE == event.type()) { |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 212 | FlowClassifier flowClassifier = ((VtnRscEventFeedback) event.subject()).flowClassifier(); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 213 | onFlowClassifierDeleted(flowClassifier); |
| 214 | } else if (VtnRscEvent.Type.FLOW_CLASSIFIER_UPDATE == event.type()) { |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 215 | FlowClassifier flowClassifier = ((VtnRscEventFeedback) event.subject()).flowClassifier(); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 216 | onFlowClassifierDeleted(flowClassifier); |
| 217 | onFlowClassifierCreated(flowClassifier); |
| 218 | } else if (VtnRscEvent.Type.PORT_CHAIN_PUT == event.type()) { |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 219 | PortChain portChain = (PortChain) ((VtnRscEventFeedback) event.subject()).portChain(); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 220 | onPortChainCreated(portChain); |
| 221 | } else if (VtnRscEvent.Type.PORT_CHAIN_DELETE == event.type()) { |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 222 | PortChain portChain = (PortChain) ((VtnRscEventFeedback) event.subject()).portChain(); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 223 | onPortChainDeleted(portChain); |
| 224 | } else if (VtnRscEvent.Type.PORT_CHAIN_UPDATE == event.type()) { |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 225 | PortChain portChain = (PortChain) ((VtnRscEventFeedback) event.subject()).portChain(); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 226 | onPortChainDeleted(portChain); |
| 227 | onPortChainCreated(portChain); |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 232 | @Override |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 233 | public void onPortPairCreated(PortPair portPair) { |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 234 | log.debug("onPortPairCreated"); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 235 | // TODO: Modify forwarding rule on port-pair creation. |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | @Override |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 239 | public void onPortPairDeleted(PortPair portPair) { |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 240 | log.debug("onPortPairDeleted"); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 241 | // TODO: Modify forwarding rule on port-pair deletion. |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | @Override |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 245 | public void onPortPairGroupCreated(PortPairGroup portPairGroup) { |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 246 | log.debug("onPortPairGroupCreated"); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 247 | // TODO: Modify forwarding rule on port-pair-group creation. |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | @Override |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 251 | public void onPortPairGroupDeleted(PortPairGroup portPairGroup) { |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 252 | log.debug("onPortPairGroupDeleted"); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 253 | // TODO: Modify forwarding rule on port-pair-group deletion. |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | @Override |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 257 | public void onFlowClassifierCreated(FlowClassifier flowClassifier) { |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 258 | log.debug("onFlowClassifierCreated"); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 259 | // TODO: Modify forwarding rule on flow-classifier creation. |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | @Override |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 263 | public void onFlowClassifierDeleted(FlowClassifier flowClassifier) { |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 264 | log.debug("onFlowClassifierDeleted"); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 265 | // TODO: Modify forwarding rule on flow-classifier deletion. |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | @Override |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 269 | public void onPortChainCreated(PortChain portChain) { |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 270 | NshServicePathId nshSpi; |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 271 | log.info("onPortChainCreated"); |
| 272 | if (nshSpiPortChainMap.containsKey(portChain.portChainId())) { |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 273 | nshSpi = NshServicePathId.of(nshSpiPortChainMap.get(portChain.portChainId())); |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 274 | } else { |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 275 | int id = getNextNshSpi(); |
| 276 | if (id > MAX_NSH_SPI_ID) { |
| 277 | log.error("Reached max limit of service path index." |
| 278 | + "Failed to install SFC for port chain {}", portChain.portChainId().toString()); |
| 279 | return; |
| 280 | } |
| 281 | nshSpi = NshServicePathId.of(id); |
| 282 | nshSpiPortChainMap.put(portChain.portChainId(), new Integer(id)); |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 283 | } |
| 284 | |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 285 | // Install classifier rule to send the packet to controller |
| 286 | flowClassifierInstaller.installFlowClassifier(portChain, nshSpi); |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | @Override |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 290 | public void onPortChainDeleted(PortChain portChain) { |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 291 | log.info("onPortChainDeleted"); |
| 292 | if (!nshSpiPortChainMap.containsKey(portChain.portChainId())) { |
| 293 | throw new ItemNotFoundException("Unable to find NSH SPI"); |
| 294 | } |
| 295 | |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 296 | int nshSpiId = nshSpiPortChainMap.get(portChain.portChainId()); |
| 297 | // Uninstall classifier rules |
| 298 | flowClassifierInstaller.unInstallFlowClassifier(portChain, NshServicePathId.of(nshSpiId)); |
| 299 | // remove from nshSpiPortChainMap and add to nshSpiIdFreeList |
| 300 | nshSpiPortChainMap.remove(portChain.portChainId()); |
| 301 | nshSpiIdFreeList.add(nshSpiId); |
Mahesh Poojary Huawei | 15092f6 | 2015-12-10 11:09:02 +0530 | [diff] [blame] | 302 | |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 303 | // Uninstall load balanced classifier and forwarding rules. |
| 304 | NshServicePathId nshSpi; |
| 305 | LoadBalanceId id; |
| 306 | List<LoadBalanceId> processedIdList = Lists.newArrayList(); |
| 307 | Set<FiveTuple> fiveTupleSet = portChain.getLoadBalanceIdMapKeys(); |
| 308 | for (FiveTuple fiveTuple : fiveTupleSet) { |
| 309 | id = portChain.getLoadBalanceId(fiveTuple); |
| 310 | if (processedIdList.contains(id)) { |
| 311 | // multiple five tuple can have single path. |
| 312 | continue; |
| 313 | } else { |
| 314 | processedIdList.add(id); |
| 315 | } |
| 316 | nshSpi = NshServicePathId.of(getNshServicePathId(id, nshSpiId)); |
| 317 | flowClassifierInstaller.unInstallLoadBalancedFlowClassifier(portChain, fiveTuple, nshSpi); |
| 318 | serviceFunctionForwarder.unInstallLoadBalancedForwardingRule(portChain.getLoadBalancePath(fiveTuple), |
| 319 | nshSpi); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | /** |
| 324 | * Get next nsh service path identifier. |
| 325 | * |
| 326 | * @return value of service path identifier |
| 327 | */ |
| 328 | int getNextNshSpi() { |
| 329 | // If there is any free id use it. Otherwise generate new id. |
| 330 | if (nshSpiIdFreeList.isEmpty()) { |
| 331 | return (int) nshSpiIdGenerator.getNewId(); |
| 332 | } |
| 333 | Iterator<Integer> it = nshSpiIdFreeList.iterator(); |
| 334 | Integer value = it.next(); |
| 335 | nshSpiIdFreeList.remove(value); |
| 336 | return value; |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 337 | } |
Phaneendra Manda | 5c8257b | 2016-02-03 22:07:38 +0530 | [diff] [blame] | 338 | |
| 339 | private class SfcPacketProcessor implements PacketProcessor { |
| 340 | |
Phaneendra Manda | b355503 | 2016-02-08 11:41:53 +0530 | [diff] [blame] | 341 | /** |
| 342 | * Check for given ip match with the fixed ips for the virtual port. |
| 343 | * |
| 344 | * @param vPortId virtual port id |
| 345 | * @param ip ip address to match |
| 346 | * @return true if the ip match with the fixed ips in virtual port false otherwise |
| 347 | */ |
| 348 | private boolean checkIpInVirtualPort(VirtualPortId vPortId, IpAddress ip) { |
| 349 | boolean found = false; |
| 350 | Set<FixedIp> ips = virtualPortService.getPort(vPortId).fixedIps(); |
| 351 | for (FixedIp fixedIp : ips) { |
| 352 | if (fixedIp.ip().equals(ip)) { |
| 353 | found = true; |
| 354 | break; |
| 355 | } |
| 356 | } |
| 357 | return found; |
| 358 | } |
| 359 | |
| 360 | /** |
| 361 | * Find the port chain for the received packet. |
| 362 | * |
| 363 | * @param fiveTuple five tuple info from the packet |
| 364 | * @return portChainId id of port chain |
| 365 | */ |
| 366 | private PortChainId findPortChainFromFiveTuple(FiveTuple fiveTuple) { |
| 367 | |
| 368 | PortChainId portChainId = null; |
| 369 | |
| 370 | Iterable<PortChain> portChains = portChainService.getPortChains(); |
| 371 | if (portChains == null) { |
| 372 | log.error("Could not retrive port chain list"); |
| 373 | } |
| 374 | |
| 375 | // Identify the port chain to which the packet belongs |
| 376 | for (final PortChain portChain : portChains) { |
| 377 | |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 378 | if (!portChain.tenantId().equals(fiveTuple.tenantId())) { |
| 379 | continue; |
| 380 | } |
| 381 | |
Phaneendra Manda | b355503 | 2016-02-08 11:41:53 +0530 | [diff] [blame] | 382 | Iterable<FlowClassifierId> flowClassifiers = portChain.flowClassifiers(); |
| 383 | |
| 384 | // One port chain can have multiple flow classifiers. |
| 385 | for (final FlowClassifierId flowClassifierId : flowClassifiers) { |
| 386 | |
| 387 | FlowClassifier flowClassifier = flowClassifierService.getFlowClassifier(flowClassifierId); |
| 388 | boolean match = false; |
| 389 | // Check whether protocol is set in flow classifier |
| 390 | if (flowClassifier.protocol() != null) { |
| 391 | if ((flowClassifier.protocol().equals("TCP") && fiveTuple.protocol() == IPv4.PROTOCOL_TCP) || |
| 392 | (flowClassifier.protocol().equals("UDP") && |
| 393 | fiveTuple.protocol() == IPv4.PROTOCOL_UDP)) { |
| 394 | match = true; |
| 395 | } else { |
| 396 | continue; |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | // Check whether source ip prefix is set in flow classifier |
| 401 | if (flowClassifier.srcIpPrefix() != null) { |
| 402 | if (flowClassifier.srcIpPrefix().contains(fiveTuple.ipSrc())) { |
| 403 | match = true; |
| 404 | } else { |
| 405 | continue; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | // Check whether destination ip prefix is set in flow classifier |
| 410 | if (flowClassifier.dstIpPrefix() != null) { |
| 411 | if (flowClassifier.dstIpPrefix().contains(fiveTuple.ipDst())) { |
| 412 | match = true; |
| 413 | } else { |
| 414 | continue; |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | // Check whether source port is set in flow classifier |
| 419 | if (fiveTuple.portSrc().toLong() >= flowClassifier.minSrcPortRange() || |
| 420 | fiveTuple.portSrc().toLong() <= flowClassifier.maxSrcPortRange()) { |
| 421 | match = true; |
| 422 | } else { |
| 423 | continue; |
| 424 | } |
| 425 | |
| 426 | // Check whether destination port is set in flow classifier |
| 427 | if (fiveTuple.portDst().toLong() >= flowClassifier.minSrcPortRange() || |
| 428 | fiveTuple.portDst().toLong() <= flowClassifier.maxSrcPortRange()) { |
| 429 | match = true; |
| 430 | } else { |
| 431 | continue; |
| 432 | } |
| 433 | |
| 434 | // Check whether neutron source port is set in flow classfier |
| 435 | if ((flowClassifier.srcPort() != null) && (!flowClassifier.srcPort().portId().isEmpty())) { |
| 436 | match = checkIpInVirtualPort(VirtualPortId.portId(flowClassifier.srcPort().portId()), |
| 437 | fiveTuple.ipSrc()); |
| 438 | if (!match) { |
| 439 | continue; |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | // Check whether destination neutron destination port is set in flow classifier |
| 444 | if ((flowClassifier.dstPort() != null) && (!flowClassifier.dstPort().portId().isEmpty())) { |
| 445 | match = checkIpInVirtualPort(VirtualPortId.portId(flowClassifier.dstPort().portId()), |
| 446 | fiveTuple.ipDst()); |
| 447 | if (!match) { |
| 448 | continue; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | if (match) { |
| 453 | portChainId = portChain.portChainId(); |
| 454 | break; |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | return portChainId; |
| 459 | } |
| 460 | |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 461 | /** |
| 462 | * Find the load balanced path set it to port chain for the given five tuple. |
| 463 | * |
| 464 | * @param portChainId port chain id |
| 465 | * @param fiveTuple five tuple info |
| 466 | * @return load balance id |
| 467 | */ |
| 468 | private LoadBalanceId loadBalanceSfc(PortChainId portChainId, FiveTuple fiveTuple) { |
| 469 | |
| 470 | // Get the port chain |
| 471 | PortChain portChain = portChainService.getPortChain(portChainId); |
| 472 | List<PortPairId> loadBalancePath = Lists.newArrayList(); |
| 473 | LoadBalanceId id; |
| 474 | int paths = portChain.getLoadBalancePathSize(); |
| 475 | if (paths >= MAX_LOAD_BALANCE_ID) { |
| 476 | log.info("Max limit reached for load balance paths. " |
| 477 | + "Reusing the created path for port chain {} with five tuple {}", |
| 478 | portChainId, fiveTuple); |
| 479 | id = LoadBalanceId.of((byte) ((paths + 1) % MAX_LOAD_BALANCE_ID)); |
| 480 | portChain.addLoadBalancePath(fiveTuple, id, portChain.getLoadBalancePath(id)); |
| 481 | } |
| 482 | |
| 483 | // Get the list of port pair groups from port chain |
| 484 | Iterable<PortPairGroupId> portPairGroups = portChain.portPairGroups(); |
| 485 | for (final PortPairGroupId portPairGroupId : portPairGroups) { |
| 486 | PortPairGroup portPairGroup = portPairGroupService.getPortPairGroup(portPairGroupId); |
| 487 | |
| 488 | // Get the list of port pair ids from port pair group. |
| 489 | Iterable<PortPairId> portPairs = portPairGroup.portPairs(); |
| 490 | int minLoad = 0xFFF; |
| 491 | PortPairId minLoadPortPairId = null; |
| 492 | for (final PortPairId portPairId : portPairs) { |
| 493 | int load = portPairGroup.getLoad(portPairId); |
| 494 | if (load == 0) { |
| 495 | minLoadPortPairId = portPairId; |
| 496 | break; |
| 497 | } else { |
| 498 | // Check the port pair which has min load. |
| 499 | if (load < minLoad) { |
| 500 | minLoad = load; |
| 501 | minLoadPortPairId = portPairId; |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | if (minLoadPortPairId != null) { |
| 506 | loadBalancePath.add(minLoadPortPairId); |
| 507 | portPairGroup.addLoad(minLoadPortPairId); |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | // Check if the path already exists, if not create a new id |
| 512 | Optional<LoadBalanceId> output = portChain.matchPath(loadBalancePath); |
| 513 | if (output.isPresent()) { |
| 514 | id = output.get(); |
| 515 | } else { |
| 516 | id = LoadBalanceId.of((byte) (paths + 1)); |
| 517 | } |
| 518 | |
| 519 | portChain.addLoadBalancePath(fiveTuple, id, loadBalancePath); |
| 520 | return id; |
| 521 | } |
Phaneendra Manda | b355503 | 2016-02-08 11:41:53 +0530 | [diff] [blame] | 522 | |
| 523 | /** |
| 524 | * Get the tenant id for the given mac address. |
| 525 | * |
| 526 | * @param mac mac address |
| 527 | * @return tenantId tenant id for the given mac address |
| 528 | */ |
| 529 | private TenantId getTenantId(MacAddress mac) { |
| 530 | Collection<VirtualPort> virtualPorts = virtualPortService.getPorts(); |
| 531 | for (VirtualPort virtualPort : virtualPorts) { |
| 532 | if (virtualPort.macAddress().equals(mac)) { |
| 533 | return virtualPort.tenantId(); |
| 534 | } |
| 535 | } |
| 536 | return null; |
| 537 | } |
| 538 | |
Phaneendra Manda | 5c8257b | 2016-02-03 22:07:38 +0530 | [diff] [blame] | 539 | @Override |
| 540 | public void process(PacketContext context) { |
| 541 | Ethernet packet = context.inPacket().parsed(); |
| 542 | if (packet == null) { |
| 543 | return; |
| 544 | } |
Phaneendra Manda | b355503 | 2016-02-08 11:41:53 +0530 | [diff] [blame] | 545 | // get the five tuple parameters for the packet |
Phaneendra Manda | 5c8257b | 2016-02-03 22:07:38 +0530 | [diff] [blame] | 546 | short ethType = packet.getEtherType(); |
Phaneendra Manda | b355503 | 2016-02-08 11:41:53 +0530 | [diff] [blame] | 547 | IpAddress ipSrc = null; |
| 548 | IpAddress ipDst = null; |
| 549 | int portSrc = 0; |
| 550 | int portDst = 0; |
| 551 | byte protocol = 0; |
| 552 | MacAddress macSrc = packet.getSourceMAC(); |
| 553 | TenantId tenantId = getTenantId(macSrc); |
Phaneendra Manda | 5c8257b | 2016-02-03 22:07:38 +0530 | [diff] [blame] | 554 | |
| 555 | if (ethType == Ethernet.TYPE_IPV4) { |
| 556 | IPv4 ipv4Packet = (IPv4) packet.getPayload(); |
| 557 | ipSrc = IpAddress.valueOf(ipv4Packet.getSourceAddress()); |
| 558 | ipDst = IpAddress.valueOf(ipv4Packet.getDestinationAddress()); |
Phaneendra Manda | b355503 | 2016-02-08 11:41:53 +0530 | [diff] [blame] | 559 | protocol = ipv4Packet.getProtocol(); |
| 560 | if (protocol == IPv4.PROTOCOL_TCP) { |
| 561 | TCP tcpPacket = (TCP) ipv4Packet.getPayload(); |
| 562 | portSrc = tcpPacket.getSourcePort(); |
| 563 | portDst = tcpPacket.getDestinationPort(); |
| 564 | } else if (protocol == IPv4.PROTOCOL_UDP) { |
| 565 | UDP udpPacket = (UDP) ipv4Packet.getPayload(); |
| 566 | portSrc = udpPacket.getSourcePort(); |
| 567 | portDst = udpPacket.getDestinationPort(); |
| 568 | } |
Phaneendra Manda | 5c8257b | 2016-02-03 22:07:38 +0530 | [diff] [blame] | 569 | } else if (ethType == Ethernet.TYPE_IPV6) { |
Phaneendra Manda | b355503 | 2016-02-08 11:41:53 +0530 | [diff] [blame] | 570 | return; |
Phaneendra Manda | 5c8257b | 2016-02-03 22:07:38 +0530 | [diff] [blame] | 571 | } |
| 572 | |
Phaneendra Manda | b355503 | 2016-02-08 11:41:53 +0530 | [diff] [blame] | 573 | |
| 574 | FiveTuple fiveTuple = DefaultFiveTuple.builder() |
| 575 | .setIpSrc(ipSrc) |
| 576 | .setIpDst(ipDst) |
| 577 | .setPortSrc(PortNumber.portNumber(portSrc)) |
| 578 | .setPortDst(PortNumber.portNumber(portDst)) |
| 579 | .setProtocol(protocol) |
| 580 | .setTenantId(tenantId) |
| 581 | .build(); |
| 582 | |
| 583 | PortChainId portChainId = findPortChainFromFiveTuple(fiveTuple); |
| 584 | |
| 585 | if (portChainId == null) { |
| 586 | log.error("Packet does not match with any classifier"); |
| 587 | return; |
| 588 | } |
| 589 | |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 590 | // Once the 5 tuple and port chain are identified, give this input for load balancing |
| 591 | LoadBalanceId id = loadBalanceSfc(portChainId, fiveTuple); |
| 592 | // Get nsh service path index |
| 593 | NshServicePathId nshSpi; |
| 594 | PortChain portChain = portChainService.getPortChain(portChainId); |
| 595 | if (nshSpiPortChainMap.containsKey(portChain.portChainId())) { |
| 596 | int nshSpiId = nshSpiPortChainMap.get(portChain.portChainId()); |
| 597 | nshSpi = NshServicePathId.of(getNshServicePathId(id, nshSpiId)); |
| 598 | } else { |
| 599 | int nshSpiId = getNextNshSpi(); |
| 600 | if (nshSpiId > MAX_NSH_SPI_ID) { |
| 601 | log.error("Reached max limit of service path index." |
| 602 | + "Failed to install SFC for port chain {}", portChain.portChainId()); |
| 603 | return; |
| 604 | } |
| 605 | nshSpi = NshServicePathId.of(getNshServicePathId(id, nshSpiId)); |
| 606 | nshSpiPortChainMap.put(portChain.portChainId(), new Integer(nshSpiId)); |
| 607 | } |
Phaneendra Manda | b355503 | 2016-02-08 11:41:53 +0530 | [diff] [blame] | 608 | // download the required flow rules for classifier and forwarding |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 609 | // install in OVS. |
| 610 | ConnectPoint connectPoint = flowClassifierInstaller.installLoadBalancedFlowClassifier(portChain, |
| 611 | fiveTuple, nshSpi); |
| 612 | serviceFunctionForwarder.installLoadBalancedForwardingRule(portChain.getLoadBalancePath(fiveTuple), |
| 613 | nshSpi); |
| 614 | sendPacket(context, connectPoint); |
Phaneendra Manda | 5c8257b | 2016-02-03 22:07:38 +0530 | [diff] [blame] | 615 | } |
Phaneendra Manda | 275ff0c | 2016-02-25 11:50:24 +0530 | [diff] [blame] | 616 | |
| 617 | /** |
| 618 | * Send packet back to classifier. |
| 619 | * |
| 620 | * @param context packet context |
| 621 | * @param connectPoint connect point of first service function |
| 622 | */ |
| 623 | private void sendPacket(PacketContext context, ConnectPoint connectPoint) { |
| 624 | |
| 625 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build(); |
| 626 | OutboundPacket packet = new DefaultOutboundPacket(connectPoint.deviceId(), treatment, |
| 627 | context.inPacket().unparsed()); |
| 628 | packetService.emit(packet); |
| 629 | log.trace("Sending packet: {}", packet); |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | /** |
| 634 | * Encapsulate 5 bit load balance id to nsh spi. |
| 635 | * |
| 636 | * @param id load balance identifier |
| 637 | * @param nshSpiId nsh service path index |
| 638 | * @return updated service path index |
| 639 | */ |
| 640 | protected int getNshServicePathId(LoadBalanceId id, int nshSpiId) { |
| 641 | int nshSpiNew = nshSpiId << 5; |
| 642 | nshSpiNew = nshSpiNew | id.loadBalanceId(); |
| 643 | return nshSpiNew; |
Phaneendra Manda | 5c8257b | 2016-02-03 22:07:38 +0530 | [diff] [blame] | 644 | } |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame] | 645 | } |