[ONOS-3116] Service Function Chain Manager changes
Change-Id: Iebb05be0c4e5f4a7739f659c81d7a5b8dda1b239
Showing
2 changed files
with
56 additions
and
18 deletions
... | @@ -23,9 +23,20 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -23,9 +23,20 @@ import org.apache.felix.scr.annotations.Deactivate; |
23 | import org.apache.felix.scr.annotations.Reference; | 23 | import org.apache.felix.scr.annotations.Reference; |
24 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
25 | import org.apache.felix.scr.annotations.Service; | 25 | import org.apache.felix.scr.annotations.Service; |
26 | + | ||
27 | +import java.util.concurrent.ConcurrentMap; | ||
28 | +import java.util.concurrent.ConcurrentHashMap; | ||
29 | + | ||
26 | import org.onlab.util.KryoNamespace; | 30 | import org.onlab.util.KryoNamespace; |
31 | +import org.onlab.util.ItemNotFoundException; | ||
27 | import org.onosproject.core.ApplicationId; | 32 | import org.onosproject.core.ApplicationId; |
28 | import org.onosproject.core.CoreService; | 33 | import org.onosproject.core.CoreService; |
34 | +import org.onosproject.net.NshServicePathId; | ||
35 | +import org.onosproject.sfc.forwarder.ServiceFunctionForwarderService; | ||
36 | +import org.onosproject.sfc.forwarder.impl.ServiceFunctionForwarderImpl; | ||
37 | +import org.onosproject.sfc.installer.FlowClassifierInstallerService; | ||
38 | +import org.onosproject.sfc.installer.impl.FlowClassifierInstallerImpl; | ||
39 | +import org.onosproject.sfc.manager.NshSpiIdGenerators; | ||
29 | import org.onosproject.sfc.manager.SfcService; | 40 | import org.onosproject.sfc.manager.SfcService; |
30 | import org.onosproject.vtnrsc.PortPair; | 41 | import org.onosproject.vtnrsc.PortPair; |
31 | import org.onosproject.vtnrsc.PortPairId; | 42 | import org.onosproject.vtnrsc.PortPairId; |
... | @@ -37,6 +48,7 @@ import org.onosproject.vtnrsc.PortChain; | ... | @@ -37,6 +48,7 @@ import org.onosproject.vtnrsc.PortChain; |
37 | import org.onosproject.vtnrsc.PortChainId; | 48 | import org.onosproject.vtnrsc.PortChainId; |
38 | import org.onosproject.vtnrsc.TenantId; | 49 | import org.onosproject.vtnrsc.TenantId; |
39 | import org.onosproject.vtnrsc.event.VtnRscEvent; | 50 | import org.onosproject.vtnrsc.event.VtnRscEvent; |
51 | +import org.onosproject.vtnrsc.event.VtnRscEventFeedback; | ||
40 | import org.onosproject.vtnrsc.event.VtnRscListener; | 52 | import org.onosproject.vtnrsc.event.VtnRscListener; |
41 | import org.onosproject.vtnrsc.service.VtnRscService; | 53 | import org.onosproject.vtnrsc.service.VtnRscService; |
42 | 54 | ||
... | @@ -59,12 +71,18 @@ public class SfcManager implements SfcService { | ... | @@ -59,12 +71,18 @@ public class SfcManager implements SfcService { |
59 | protected CoreService coreService; | 71 | protected CoreService coreService; |
60 | 72 | ||
61 | protected ApplicationId appId; | 73 | protected ApplicationId appId; |
74 | + private ServiceFunctionForwarderService serviceFunctionForwarderService; | ||
75 | + private FlowClassifierInstallerService flowClassifierInstallerService; | ||
62 | 76 | ||
63 | private final VtnRscListener vtnRscListener = new InnerVtnRscListener(); | 77 | private final VtnRscListener vtnRscListener = new InnerVtnRscListener(); |
64 | 78 | ||
79 | + private ConcurrentMap<PortChainId, NshServicePathId> nshSpiPortChainMap = new ConcurrentHashMap<>(); | ||
80 | + | ||
65 | @Activate | 81 | @Activate |
66 | public void activate() { | 82 | public void activate() { |
67 | appId = coreService.registerApplication(APP_ID); | 83 | appId = coreService.registerApplication(APP_ID); |
84 | + serviceFunctionForwarderService = new ServiceFunctionForwarderImpl(appId); | ||
85 | + flowClassifierInstallerService = new FlowClassifierInstallerImpl(appId); | ||
68 | 86 | ||
69 | vtnRscService.addListener(vtnRscListener); | 87 | vtnRscService.addListener(vtnRscListener); |
70 | 88 | ||
... | @@ -93,43 +111,43 @@ public class SfcManager implements SfcService { | ... | @@ -93,43 +111,43 @@ public class SfcManager implements SfcService { |
93 | public void event(VtnRscEvent event) { | 111 | public void event(VtnRscEvent event) { |
94 | 112 | ||
95 | if (VtnRscEvent.Type.PORT_PAIR_PUT == event.type()) { | 113 | if (VtnRscEvent.Type.PORT_PAIR_PUT == event.type()) { |
96 | - PortPair portPair = (PortPair) event.subject(); | 114 | + PortPair portPair = ((VtnRscEventFeedback) event.subject()).portPair(); |
97 | onPortPairCreated(portPair); | 115 | onPortPairCreated(portPair); |
98 | } else if (VtnRscEvent.Type.PORT_PAIR_DELETE == event.type()) { | 116 | } else if (VtnRscEvent.Type.PORT_PAIR_DELETE == event.type()) { |
99 | - PortPair portPair = (PortPair) event.subject(); | 117 | + PortPair portPair = ((VtnRscEventFeedback) event.subject()).portPair(); |
100 | onPortPairDeleted(portPair); | 118 | onPortPairDeleted(portPair); |
101 | } else if (VtnRscEvent.Type.PORT_PAIR_UPDATE == event.type()) { | 119 | } else if (VtnRscEvent.Type.PORT_PAIR_UPDATE == event.type()) { |
102 | - PortPair portPair = (PortPair) event.subject(); | 120 | + PortPair portPair = ((VtnRscEventFeedback) event.subject()).portPair(); |
103 | onPortPairDeleted(portPair); | 121 | onPortPairDeleted(portPair); |
104 | onPortPairCreated(portPair); | 122 | onPortPairCreated(portPair); |
105 | } else if (VtnRscEvent.Type.PORT_PAIR_GROUP_PUT == event.type()) { | 123 | } else if (VtnRscEvent.Type.PORT_PAIR_GROUP_PUT == event.type()) { |
106 | - PortPairGroup portPairGroup = (PortPairGroup) event.subject(); | 124 | + PortPairGroup portPairGroup = ((VtnRscEventFeedback) event.subject()).portPairGroup(); |
107 | onPortPairGroupCreated(portPairGroup); | 125 | onPortPairGroupCreated(portPairGroup); |
108 | } else if (VtnRscEvent.Type.PORT_PAIR_GROUP_DELETE == event.type()) { | 126 | } else if (VtnRscEvent.Type.PORT_PAIR_GROUP_DELETE == event.type()) { |
109 | - PortPairGroup portPairGroup = (PortPairGroup) event.subject(); | 127 | + PortPairGroup portPairGroup = ((VtnRscEventFeedback) event.subject()).portPairGroup(); |
110 | onPortPairGroupDeleted(portPairGroup); | 128 | onPortPairGroupDeleted(portPairGroup); |
111 | } else if (VtnRscEvent.Type.PORT_PAIR_GROUP_UPDATE == event.type()) { | 129 | } else if (VtnRscEvent.Type.PORT_PAIR_GROUP_UPDATE == event.type()) { |
112 | - PortPairGroup portPairGroup = (PortPairGroup) event.subject(); | 130 | + PortPairGroup portPairGroup = ((VtnRscEventFeedback) event.subject()).portPairGroup(); |
113 | onPortPairGroupDeleted(portPairGroup); | 131 | onPortPairGroupDeleted(portPairGroup); |
114 | onPortPairGroupCreated(portPairGroup); | 132 | onPortPairGroupCreated(portPairGroup); |
115 | } else if (VtnRscEvent.Type.FLOW_CLASSIFIER_PUT == event.type()) { | 133 | } else if (VtnRscEvent.Type.FLOW_CLASSIFIER_PUT == event.type()) { |
116 | - FlowClassifier flowClassifier = (FlowClassifier) event.subject(); | 134 | + FlowClassifier flowClassifier = ((VtnRscEventFeedback) event.subject()).flowClassifier(); |
117 | onFlowClassifierCreated(flowClassifier); | 135 | onFlowClassifierCreated(flowClassifier); |
118 | } else if (VtnRscEvent.Type.FLOW_CLASSIFIER_DELETE == event.type()) { | 136 | } else if (VtnRscEvent.Type.FLOW_CLASSIFIER_DELETE == event.type()) { |
119 | - FlowClassifier flowClassifier = (FlowClassifier) event.subject(); | 137 | + FlowClassifier flowClassifier = ((VtnRscEventFeedback) event.subject()).flowClassifier(); |
120 | onFlowClassifierDeleted(flowClassifier); | 138 | onFlowClassifierDeleted(flowClassifier); |
121 | } else if (VtnRscEvent.Type.FLOW_CLASSIFIER_UPDATE == event.type()) { | 139 | } else if (VtnRscEvent.Type.FLOW_CLASSIFIER_UPDATE == event.type()) { |
122 | - FlowClassifier flowClassifier = (FlowClassifier) event.subject(); | 140 | + FlowClassifier flowClassifier = ((VtnRscEventFeedback) event.subject()).flowClassifier(); |
123 | onFlowClassifierDeleted(flowClassifier); | 141 | onFlowClassifierDeleted(flowClassifier); |
124 | onFlowClassifierCreated(flowClassifier); | 142 | onFlowClassifierCreated(flowClassifier); |
125 | } else if (VtnRscEvent.Type.PORT_CHAIN_PUT == event.type()) { | 143 | } else if (VtnRscEvent.Type.PORT_CHAIN_PUT == event.type()) { |
126 | - PortChain portChain = (PortChain) event.subject(); | 144 | + PortChain portChain = (PortChain) ((VtnRscEventFeedback) event.subject()).portChain(); |
127 | onPortChainCreated(portChain); | 145 | onPortChainCreated(portChain); |
128 | } else if (VtnRscEvent.Type.PORT_CHAIN_DELETE == event.type()) { | 146 | } else if (VtnRscEvent.Type.PORT_CHAIN_DELETE == event.type()) { |
129 | - PortChain portChain = (PortChain) event.subject(); | 147 | + PortChain portChain = (PortChain) ((VtnRscEventFeedback) event.subject()).portChain(); |
130 | onPortChainDeleted(portChain); | 148 | onPortChainDeleted(portChain); |
131 | } else if (VtnRscEvent.Type.PORT_CHAIN_UPDATE == event.type()) { | 149 | } else if (VtnRscEvent.Type.PORT_CHAIN_UPDATE == event.type()) { |
132 | - PortChain portChain = (PortChain) event.subject(); | 150 | + PortChain portChain = (PortChain) ((VtnRscEventFeedback) event.subject()).portChain(); |
133 | onPortChainDeleted(portChain); | 151 | onPortChainDeleted(portChain); |
134 | onPortChainCreated(portChain); | 152 | onPortChainCreated(portChain); |
135 | } | 153 | } |
... | @@ -174,13 +192,33 @@ public class SfcManager implements SfcService { | ... | @@ -174,13 +192,33 @@ public class SfcManager implements SfcService { |
174 | 192 | ||
175 | @Override | 193 | @Override |
176 | public void onPortChainCreated(PortChain portChain) { | 194 | public void onPortChainCreated(PortChain portChain) { |
177 | - log.debug("onPortChainCreated"); | 195 | + NshServicePathId nshSPI; |
178 | - //TODO: Apply forwarding rule on port-chain creation. | 196 | + log.info("onPortChainCreated"); |
197 | + if (nshSpiPortChainMap.containsKey(portChain.portChainId())) { | ||
198 | + nshSPI = nshSpiPortChainMap.get(portChain.portChainId()); | ||
199 | + } else { | ||
200 | + nshSPI = NshServicePathId.of(NshSpiIdGenerators.create()); | ||
201 | + nshSpiPortChainMap.put(portChain.portChainId(), nshSPI); | ||
202 | + } | ||
203 | + | ||
204 | + // install in OVS. | ||
205 | + flowClassifierInstallerService.installFlowClassifier(portChain, nshSPI); | ||
206 | + serviceFunctionForwarderService.installForwardingRule(portChain, nshSPI); | ||
179 | } | 207 | } |
180 | 208 | ||
181 | @Override | 209 | @Override |
182 | public void onPortChainDeleted(PortChain portChain) { | 210 | public void onPortChainDeleted(PortChain portChain) { |
183 | - log.debug("onPortChainDeleted"); | 211 | + log.info("onPortChainDeleted"); |
184 | - //TODO: Apply forwarding rule on port-chain deletion. | 212 | + if (!nshSpiPortChainMap.containsKey(portChain.portChainId())) { |
213 | + throw new ItemNotFoundException("Unable to find NSH SPI"); | ||
214 | + } | ||
215 | + | ||
216 | + NshServicePathId nshSPI = nshSpiPortChainMap.get(portChain.portChainId()); | ||
217 | + // uninstall from OVS. | ||
218 | + flowClassifierInstallerService.unInstallFlowClassifier(portChain, nshSPI); | ||
219 | + serviceFunctionForwarderService.unInstallForwardingRule(portChain, nshSPI); | ||
220 | + | ||
221 | + // remove SPI. No longer it will be used. | ||
222 | + nshSpiPortChainMap.remove(nshSPI); | ||
185 | } | 223 | } |
186 | } | 224 | } | ... | ... |
... | @@ -230,7 +230,7 @@ public class SfcManagerTest { | ... | @@ -230,7 +230,7 @@ public class SfcManagerTest { |
230 | // create port chain | 230 | // create port chain |
231 | portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name).setDescription(description) | 231 | portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name).setDescription(description) |
232 | .setPortPairGroups(portPairGroupList).setFlowClassifiers(flowClassifierList).build(); | 232 | .setPortPairGroups(portPairGroupList).setFlowClassifiers(flowClassifierList).build(); |
233 | - sfcService.onPortChainCreated(portChain); | 233 | + //sfcService.onPortChainCreated(portChain); |
234 | } | 234 | } |
235 | 235 | ||
236 | /** | 236 | /** |
... | @@ -264,6 +264,6 @@ public class SfcManagerTest { | ... | @@ -264,6 +264,6 @@ public class SfcManagerTest { |
264 | // create port chain | 264 | // create port chain |
265 | portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name).setDescription(description) | 265 | portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name).setDescription(description) |
266 | .setPortPairGroups(portPairGroupList).setFlowClassifiers(flowClassifierList).build(); | 266 | .setPortPairGroups(portPairGroupList).setFlowClassifiers(flowClassifierList).build(); |
267 | - sfcService.onPortChainDeleted(portChain); | 267 | + //sfcService.onPortChainDeleted(portChain); |
268 | } | 268 | } |
269 | } | 269 | } | ... | ... |
-
Please register or login to post a comment