[ONOS] Cherry picked from master 1.7
Change-Id: I74a0c1634f9c425af2bcb646edc3d9170b3c087c
diff --git a/providers/pcep/packet/pom.xml b/providers/pcep/packet/pom.xml
new file mode 100644
index 0000000..9f3bd5e
--- /dev/null
+++ b/providers/pcep/packet/pom.xml
@@ -0,0 +1,33 @@
+<!--
+ ~ Copyright 2016-present Open Networking Laboratory
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-pcep-providers</artifactId>
+ <version>1.6.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>onos-pcep-provider-packet</artifactId>
+ <packaging>bundle</packaging>
+ <description>PCEP packet provider</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-pcep-controller-api</artifactId>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/providers/pcep/packet/src/main/java/org/onosproject/provider/pcep/packet/impl/PcepPacketProvider.java b/providers/pcep/packet/src/main/java/org/onosproject/provider/pcep/packet/impl/PcepPacketProvider.java
new file mode 100644
index 0000000..48f2408
--- /dev/null
+++ b/providers/pcep/packet/src/main/java/org/onosproject/provider/pcep/packet/impl/PcepPacketProvider.java
@@ -0,0 +1,140 @@
+package org.onosproject.provider.pcep.packet.impl;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.onlab.packet.Ethernet;
+import org.onlab.packet.IPv4;
+import org.onlab.packet.TCP;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.packet.DefaultInboundPacket;
+import org.onosproject.net.packet.DefaultPacketContext;
+import org.onosproject.net.packet.InboundPacket;
+import org.onosproject.net.packet.OutboundPacket;
+import org.onosproject.net.packet.PacketProvider;
+import org.onosproject.net.packet.PacketProviderRegistry;
+import org.onosproject.net.packet.PacketProviderService;
+import org.onosproject.net.provider.AbstractProvider;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.pcep.controller.PccId;
+import org.onosproject.pcep.controller.PcepClientController;
+import org.onosproject.pcep.controller.PcepPacketListener;
+import org.slf4j.Logger;
+
+/**
+ * Provider which uses an PCEP controller to process packets.
+ */
+@Component(immediate = true)
+@Service
+public class PcepPacketProvider extends AbstractProvider implements PacketProvider {
+
+ private static final Logger log = getLogger(PcepPacketProvider.class);
+ static final String PROVIDER_ID = "org.onosproject.provider.packet.pcep";
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected PacketProviderRegistry packetProviderRegistry;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected PcepClientController pcepClientController;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DeviceService deviceService;
+
+ PacketProviderService packetProviderService;
+
+ private InnerPacketProvider listener = new InnerPacketProvider();
+ public static final String LSRID = "lsrId";
+ public static final int PCEP_PORT = 4189;
+
+ /**
+ * Creates a Packet provider.
+ */
+ public PcepPacketProvider() {
+ super(new ProviderId("pcep", PROVIDER_ID));
+ }
+
+ @Activate
+ public void activate() {
+ packetProviderService = packetProviderRegistry.register(this);
+ pcepClientController.addPacketListener(listener);
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ packetProviderRegistry.unregister(this);
+ pcepClientController.removePacketListener(listener);
+ log.info("Stopped");
+ }
+
+ private class InnerPacketProvider implements PcepPacketListener {
+ @Override
+ public void sendPacketIn(PccId pccId) {
+ TCP tcp = new TCP();
+ // Set the well known PCEP port. To be used to decide to process/discard the packet while processing.
+ tcp.setDestinationPort(PCEP_PORT);
+
+ IPv4 ipv4 = new IPv4();
+ ipv4.setProtocol(IPv4.PROTOCOL_TCP);
+ ipv4.setPayload(tcp);
+
+ Ethernet eth = new Ethernet();
+ eth.setEtherType(Ethernet.TYPE_IPV4);
+ eth.setPayload(ipv4);
+
+ // Get lsrId of the PCEP client from the PCC ID. Session info is based on lsrID.
+ String lsrId = String.valueOf(pccId.ipAddress());
+ DeviceId pccDeviceId = null;
+
+ // Find PCC deviceID from lsrId stored as annotations
+ Iterable<Device> devices = deviceService.getAvailableDevices();
+ for (Device dev : devices) {
+ if ("L3".equals(dev.annotations().value(AnnotationKeys.TYPE))
+ && lsrId.equals(dev.annotations().value(LSRID))) {
+ pccDeviceId = dev.id();
+ break;
+ }
+ }
+
+ if (pccDeviceId == null) {
+ return;
+ }
+
+ InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(pccDeviceId,
+ PortNumber.portNumber(PCEP_PORT)),
+ eth, null);
+
+ packetProviderService.processPacket(new PcepPacketContext(inPkt, null));
+ }
+ }
+
+ // Minimal PacketContext to make core and applications happy.
+ private final class PcepPacketContext extends DefaultPacketContext {
+ private PcepPacketContext(InboundPacket inPkt, OutboundPacket outPkt) {
+ super(System.currentTimeMillis(), inPkt, outPkt, false);
+ }
+
+ @Override
+ public void send() {
+ // We don't send anything out.
+ return;
+ }
+ }
+
+ @Override
+ public void emit(OutboundPacket packet) {
+ // Nothing to emit
+ return;
+
+ }
+}
diff --git a/providers/pcep/packet/src/main/java/org/onosproject/provider/pcep/packet/impl/package-info.java b/providers/pcep/packet/src/main/java/org/onosproject/provider/pcep/packet/impl/package-info.java
new file mode 100644
index 0000000..8e1ab9a
--- /dev/null
+++ b/providers/pcep/packet/src/main/java/org/onosproject/provider/pcep/packet/impl/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ *Provider that uses PCEP controller as a means to send packets.
+ */
+package org.onosproject.provider.pcep.packet.impl;
\ No newline at end of file