Phaneendra Manda
Committed by Gerrit Code Review

[ONOS-3832] Sfc manager register with packet subsystem

Change-Id: I8eeaadd22c82647bfb87f682306b50b7fa5926a5
...@@ -15,17 +15,31 @@ ...@@ -15,17 +15,31 @@
15 */ 15 */
16 package org.onosproject.sfc.manager.impl; 16 package org.onosproject.sfc.manager.impl;
17 17
18 +import static org.slf4j.LoggerFactory.getLogger;
19 +
20 +import java.util.concurrent.ConcurrentHashMap;
21 +import java.util.concurrent.ConcurrentMap;
22 +
18 import org.apache.felix.scr.annotations.Activate; 23 import org.apache.felix.scr.annotations.Activate;
19 import org.apache.felix.scr.annotations.Component; 24 import org.apache.felix.scr.annotations.Component;
20 import org.apache.felix.scr.annotations.Deactivate; 25 import org.apache.felix.scr.annotations.Deactivate;
21 import org.apache.felix.scr.annotations.Reference; 26 import org.apache.felix.scr.annotations.Reference;
22 import org.apache.felix.scr.annotations.ReferenceCardinality; 27 import org.apache.felix.scr.annotations.ReferenceCardinality;
23 import org.apache.felix.scr.annotations.Service; 28 import org.apache.felix.scr.annotations.Service;
29 +import org.onlab.packet.Ethernet;
30 +import org.onlab.packet.IPv4;
31 +import org.onlab.packet.IPv6;
32 +import org.onlab.packet.IpAddress;
33 +import org.onlab.packet.MacAddress;
34 +import org.onlab.packet.VlanId;
24 import org.onlab.util.ItemNotFoundException; 35 import org.onlab.util.ItemNotFoundException;
25 import org.onlab.util.KryoNamespace; 36 import org.onlab.util.KryoNamespace;
26 import org.onosproject.core.ApplicationId; 37 import org.onosproject.core.ApplicationId;
27 import org.onosproject.core.CoreService; 38 import org.onosproject.core.CoreService;
28 import org.onosproject.net.NshServicePathId; 39 import org.onosproject.net.NshServicePathId;
40 +import org.onosproject.net.packet.PacketContext;
41 +import org.onosproject.net.packet.PacketProcessor;
42 +import org.onosproject.net.packet.PacketService;
29 import org.onosproject.sfc.forwarder.ServiceFunctionForwarderService; 43 import org.onosproject.sfc.forwarder.ServiceFunctionForwarderService;
30 import org.onosproject.sfc.forwarder.impl.ServiceFunctionForwarderImpl; 44 import org.onosproject.sfc.forwarder.impl.ServiceFunctionForwarderImpl;
31 import org.onosproject.sfc.installer.FlowClassifierInstallerService; 45 import org.onosproject.sfc.installer.FlowClassifierInstallerService;
...@@ -47,11 +61,6 @@ import org.onosproject.vtnrsc.event.VtnRscListener; ...@@ -47,11 +61,6 @@ import org.onosproject.vtnrsc.event.VtnRscListener;
47 import org.onosproject.vtnrsc.service.VtnRscService; 61 import org.onosproject.vtnrsc.service.VtnRscService;
48 import org.slf4j.Logger; 62 import org.slf4j.Logger;
49 63
50 -import java.util.concurrent.ConcurrentHashMap;
51 -import java.util.concurrent.ConcurrentMap;
52 -
53 -import static org.slf4j.LoggerFactory.getLogger;
54 -
55 /** 64 /**
56 * Provides implementation of SFC Service. 65 * Provides implementation of SFC Service.
57 */ 66 */
...@@ -61,6 +70,7 @@ public class SfcManager implements SfcService { ...@@ -61,6 +70,7 @@ public class SfcManager implements SfcService {
61 70
62 private final Logger log = getLogger(getClass()); 71 private final Logger log = getLogger(getClass());
63 private static final String APP_ID = "org.onosproject.app.vtn"; 72 private static final String APP_ID = "org.onosproject.app.vtn";
73 + private static final int SFC_PRIORITY = 1000;
64 74
65 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 75 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
66 protected VtnRscService vtnRscService; 76 protected VtnRscService vtnRscService;
...@@ -68,6 +78,11 @@ public class SfcManager implements SfcService { ...@@ -68,6 +78,11 @@ public class SfcManager implements SfcService {
68 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 78 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
69 protected CoreService coreService; 79 protected CoreService coreService;
70 80
81 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
82 + protected PacketService packetService;
83 +
84 + private SfcPacketProcessor processor = new SfcPacketProcessor();
85 +
71 protected ApplicationId appId; 86 protected ApplicationId appId;
72 private ServiceFunctionForwarderService serviceFunctionForwarderService; 87 private ServiceFunctionForwarderService serviceFunctionForwarderService;
73 private FlowClassifierInstallerService flowClassifierInstallerService; 88 private FlowClassifierInstallerService flowClassifierInstallerService;
...@@ -91,13 +106,14 @@ public class SfcManager implements SfcService { ...@@ -91,13 +106,14 @@ public class SfcManager implements SfcService {
91 .register(FlowClassifierId.class) 106 .register(FlowClassifierId.class)
92 .register(PortChainId.class); 107 .register(PortChainId.class);
93 108
109 + packetService.addProcessor(processor, PacketProcessor.director(SFC_PRIORITY));
94 log.info("Started"); 110 log.info("Started");
95 } 111 }
96 112
97 @Deactivate 113 @Deactivate
98 public void deactivate() { 114 public void deactivate() {
99 vtnRscService.removeListener(vtnRscListener); 115 vtnRscService.removeListener(vtnRscListener);
100 - 116 + packetService.removeProcessor(processor);
101 log.info("Stopped"); 117 log.info("Stopped");
102 } 118 }
103 119
...@@ -219,4 +235,35 @@ public class SfcManager implements SfcService { ...@@ -219,4 +235,35 @@ public class SfcManager implements SfcService {
219 // remove SPI. No longer it will be used. 235 // remove SPI. No longer it will be used.
220 nshSpiPortChainMap.remove(nshSpi); 236 nshSpiPortChainMap.remove(nshSpi);
221 } 237 }
238 +
239 + private class SfcPacketProcessor implements PacketProcessor {
240 +
241 + @Override
242 + public void process(PacketContext context) {
243 + Ethernet packet = context.inPacket().parsed();
244 + if (packet == null) {
245 + return;
246 + }
247 + // get the five tupple parameters for the packet
248 + short ethType = packet.getEtherType();
249 + VlanId vlanId = VlanId.vlanId(packet.getVlanID());
250 + MacAddress srcMac = packet.getSourceMAC();
251 + MacAddress dstMac = packet.getDestinationMAC();
252 + IpAddress ipSrc;
253 + IpAddress ipDst;
254 +
255 + if (ethType == Ethernet.TYPE_IPV4) {
256 + IPv4 ipv4Packet = (IPv4) packet.getPayload();
257 + ipSrc = IpAddress.valueOf(ipv4Packet.getSourceAddress());
258 + ipDst = IpAddress.valueOf(ipv4Packet.getDestinationAddress());
259 + } else if (ethType == Ethernet.TYPE_IPV6) {
260 + IPv6 ipv6Packet = (IPv6) packet.getPayload();
261 + ipSrc = IpAddress.valueOf(ipv6Packet.getSourceAddress().toString());
262 + ipDst = IpAddress.valueOf(ipv6Packet.getDestinationAddress().toString());
263 + }
264 +
265 + //todo
266 + //identify the port chain to which the packet belongs
267 + }
268 + }
222 } 269 }
......