Move PCE label handling from APP to protocol.
Change-Id: I26ae21b27ac2dc9ae3302030f6860e0e371c342c
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/BasicPceccHandler.java b/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/BasicPceccHandler.java
deleted file mode 100644
index e30b966..0000000
--- a/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/BasicPceccHandler.java
+++ /dev/null
@@ -1,357 +0,0 @@
-/*
- * 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.
- */
-package org.onosproject.pce.pceservice;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.LinkedList;
-
-import org.onlab.packet.MplsLabel;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.incubator.net.resource.label.DefaultLabelResource;
-import org.onosproject.incubator.net.resource.label.LabelResource;
-import org.onosproject.incubator.net.resource.label.LabelResourceId;
-import org.onosproject.incubator.net.resource.label.LabelResourceService;
-import org.onosproject.incubator.net.tunnel.Tunnel;
-import org.onosproject.incubator.net.tunnel.TunnelId;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
-import org.onosproject.net.flow.DefaultTrafficSelector;
-import org.onosproject.net.flow.DefaultTrafficTreatment;
-import org.onosproject.net.flow.TrafficSelector;
-import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.flowobjective.DefaultForwardingObjective;
-import org.onosproject.net.flowobjective.FlowObjectiveService;
-import org.onosproject.net.flowobjective.ForwardingObjective;
-import org.onosproject.net.flowobjective.Objective;
-import org.onosproject.pce.pcestore.api.PceStore;
-import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
-import org.onosproject.pce.pcestore.PceccTunnelInfo;
-import org.onosproject.pce.pcestore.DefaultLspLocalLabelInfo;
-import org.onosproject.net.Link;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.Multimap;
-
-/**
- * Basic PCECC handler.
- * In Basic PCECC, after path computation will configure IN and OUT label to nodes.
- * [X]OUT---link----IN[Y]OUT---link-----IN[Z] where X, Y and Z are nodes.
- * For generating labels, will go thorough links in the path from Egress to Ingress.
- * In each link, will take label from destination node local pool as IN label,
- * and assign this label as OUT label to source node.
- */
-public final class BasicPceccHandler {
- private static final Logger log = LoggerFactory.getLogger(BasicPceccHandler.class);
-
- private static final String LABEL_RESOURCE_SERVICE_NULL = "Label Resource Service cannot be null";
- private static final String PCE_STORE_NULL = "PCE Store cannot be null";
- private static BasicPceccHandler crHandlerInstance = null;
- private LabelResourceService labelRsrcService;
- private PceStore pceStore;
- private FlowObjectiveService flowObjectiveService;
- private ApplicationId appId;
-
- /**
- * Initializes default values.
- */
- private BasicPceccHandler() {
- }
-
- /**
- * Returns single instance of this class.
- *
- * @return this class single instance
- */
- public static BasicPceccHandler getInstance() {
- if (crHandlerInstance == null) {
- crHandlerInstance = new BasicPceccHandler();
- }
- return crHandlerInstance;
- }
-
- /**
- * Initialization of label manager and pce store.
- *
- * @param labelRsrcService label resource service
- * @param flowObjectiveService flow objective service to push device label information
- * @param appId applicaton id
- * @param pceStore pce label store
- */
- public void initialize(LabelResourceService labelRsrcService, FlowObjectiveService flowObjectiveService,
- ApplicationId appId, PceStore pceStore) {
- this.labelRsrcService = labelRsrcService;
- this.flowObjectiveService = flowObjectiveService;
- this.appId = appId;
- this.pceStore = pceStore;
- }
-
- /**
- * Allocates labels from local resource pool and configure these (IN and OUT) labels into devices.
- *
- * @param tunnel tunnel between ingress to egress
- * @return success or failure
- */
- public boolean allocateLabel(Tunnel tunnel) {
- long applyNum = 1;
- boolean isLastLabelToPush = false;
- Collection<LabelResource> labelRscList;
-
- checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL);
- checkNotNull(pceStore, PCE_STORE_NULL);
-
- List<Link> linkList = tunnel.path().links();
- if ((linkList != null) && (linkList.size() > 0)) {
- // Sequence through reverse order to push local labels into devices
- // Generation of labels from egress to ingress
- for (ListIterator<Link> iterator = linkList.listIterator(linkList.size()); iterator.hasPrevious();) {
- Link link = iterator.previous();
- DeviceId dstDeviceId = link.dst().deviceId();
- DeviceId srcDeviceId = link.src().deviceId();
- labelRscList = labelRsrcService.applyFromDevicePool(dstDeviceId, applyNum);
- if ((labelRscList != null) && (labelRscList.size() > 0)) {
- // Link label value is taken from destination device local pool.
- // [X]OUT---link----IN[Y]OUT---link-----IN[Z] where X, Y and Z are nodes.
- // Link label value is used as OUT and IN for both ends
- // (source and destination devices) of the link.
- // Currently only one label is allocated to a device (destination device).
- // So, no need to iterate through list
- Iterator<LabelResource> labelIterator = labelRscList.iterator();
- DefaultLabelResource defaultLabelResource = (DefaultLabelResource) labelIterator.next();
- LabelResourceId labelId = defaultLabelResource.labelResourceId();
- log.debug("Allocated local label: " + labelId.toString()
- + "to device: " + defaultLabelResource.deviceId().toString());
- PortNumber dstPort = link.dst().port();
-
- // Check whether this is last link label to push
- if (!iterator.hasPrevious()) {
- isLastLabelToPush = true;
- }
-
- // Push into destination device
- // Destination device IN port is link.dst().port()
- installLocalLabelRule(dstDeviceId, labelId, dstPort, tunnel.tunnelId(), false,
- Long.valueOf(LabelType.IN_LABEL.value), Objective.Operation.ADD);
-
- // Push into source device
- // Source device OUT port will be link.dst().port(). Means its remote port used to send packet.
- installLocalLabelRule(srcDeviceId, labelId, dstPort, tunnel.tunnelId(), isLastLabelToPush,
- Long.valueOf(LabelType.OUT_LABEL.value), Objective.Operation.ADD);
-
- // Add or update pcecc tunnel info in pce store.
- updatePceccTunnelInfoInStore(srcDeviceId, dstDeviceId, labelId, dstPort,
- tunnel, isLastLabelToPush);
- } else {
- log.error("Unable to allocate label to device id {}.", dstDeviceId.toString());
- releaseLabel(tunnel);
- return false;
- }
- }
- } else {
- log.error("Tunnel {} is having empty links.", tunnel.toString());
- return false;
- }
-
- return true;
- }
-
- /**
- * Updates list of local labels of PCECC tunnel info in pce store.
- *
- * @param srcDeviceId source device in a link
- * @param dstDeviceId destination device in a link
- * @param labelId label id of a link
- * @param dstPort destination device port number of a link
- * @param tunnel tunnel
- * @param isLastLabelToPush indicates this is the last label to push in Basic PCECC case
- */
- public void updatePceccTunnelInfoInStore(DeviceId srcDeviceId, DeviceId dstDeviceId, LabelResourceId labelId,
- PortNumber dstPort, Tunnel tunnel, boolean isLastLabelToPush) {
- // First try to retrieve device from store and update its label id if it is exists,
- // otherwise add it
- boolean dstDeviceUpdated = false;
- boolean srcDeviceUpdated = false;
-
- PceccTunnelInfo pceccTunnelInfo = pceStore.getTunnelInfo(tunnel.tunnelId());
- List<LspLocalLabelInfo> lspLabelInfoList;
- if (pceccTunnelInfo != null) {
- lspLabelInfoList = pceccTunnelInfo.lspLocalLabelInfoList();
- if ((lspLabelInfoList != null) && (lspLabelInfoList.size() > 0)) {
- for (int i = 0; i < lspLabelInfoList.size(); ++i) {
- LspLocalLabelInfo lspLocalLabelInfo =
- lspLabelInfoList.get(i);
- LspLocalLabelInfo.Builder lspLocalLabelInfoBuilder = null;
- if (dstDeviceId.equals(lspLocalLabelInfo.deviceId())) {
- lspLocalLabelInfoBuilder = DefaultLspLocalLabelInfo.builder(lspLocalLabelInfo);
- lspLocalLabelInfoBuilder.inLabelId(labelId);
- // Destination device IN port will be link destination port
- lspLocalLabelInfoBuilder.inPort(dstPort);
- dstDeviceUpdated = true;
- } else if (srcDeviceId.equals(lspLocalLabelInfo.deviceId())) {
- lspLocalLabelInfoBuilder = DefaultLspLocalLabelInfo.builder(lspLocalLabelInfo);
- lspLocalLabelInfoBuilder.outLabelId(labelId);
- // Source device OUT port will be link destination (remote) port
- lspLocalLabelInfoBuilder.outPort(dstPort);
- srcDeviceUpdated = true;
- }
-
- // Update
- if ((lspLocalLabelInfoBuilder != null) && (dstDeviceUpdated || srcDeviceUpdated)) {
- lspLabelInfoList.set(i, lspLocalLabelInfoBuilder.build());
- }
- }
- }
- }
-
- // If it is not found in store then add it to store
- if (!dstDeviceUpdated || !srcDeviceUpdated) {
- // If tunnel info itself not available then create new one, otherwise add node to list.
- if (pceccTunnelInfo == null) {
- pceccTunnelInfo = new PceccTunnelInfo();
- lspLabelInfoList = new LinkedList<>();
- } else {
- lspLabelInfoList = pceccTunnelInfo.lspLocalLabelInfoList();
- if (lspLabelInfoList == null) {
- lspLabelInfoList = new LinkedList<>();
- }
- }
-
- if (!dstDeviceUpdated) {
- LspLocalLabelInfo lspLocalLabelInfo = DefaultLspLocalLabelInfo.builder()
- .deviceId(dstDeviceId)
- .inLabelId(labelId)
- .outLabelId(null)
- .inPort(dstPort) // Destination device IN port will be link destination port
- .outPort(null)
- .build();
- lspLabelInfoList.add(lspLocalLabelInfo);
- }
-
- if (!srcDeviceUpdated) {
- LspLocalLabelInfo lspLocalLabelInfo = DefaultLspLocalLabelInfo.builder()
- .deviceId(srcDeviceId)
- .inLabelId(null)
- .outLabelId(labelId)
- .inPort(null)
- .outPort(dstPort) // Source device OUT port will be link destination (remote) port
- .build();
- lspLabelInfoList.add(lspLocalLabelInfo);
- }
-
- pceccTunnelInfo.lspLocalLabelInfoList(lspLabelInfoList);
- pceStore.addTunnelInfo(tunnel.tunnelId(), pceccTunnelInfo);
- }
- }
-
- /**
- * Deallocates unused labels to device pools.
- *
- * @param tunnel tunnel between ingress to egress
- */
- public void releaseLabel(Tunnel tunnel) {
-
- checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL);
- checkNotNull(pceStore, PCE_STORE_NULL);
-
- Multimap<DeviceId, LabelResource> release = ArrayListMultimap.create();
- PceccTunnelInfo pceccTunnelInfo = pceStore.getTunnelInfo(tunnel.tunnelId());
- if (pceccTunnelInfo != null) {
- List<LspLocalLabelInfo> lspLocalLabelInfoList = pceccTunnelInfo.lspLocalLabelInfoList();
- if ((lspLocalLabelInfoList != null) && (lspLocalLabelInfoList.size() > 0)) {
- for (Iterator<LspLocalLabelInfo> iterator = lspLocalLabelInfoList.iterator(); iterator.hasNext();) {
- LspLocalLabelInfo lspLocalLabelInfo = iterator.next();
- DeviceId deviceId = lspLocalLabelInfo.deviceId();
- LabelResourceId inLabelId = lspLocalLabelInfo.inLabelId();
- LabelResourceId outLabelId = lspLocalLabelInfo.outLabelId();
- PortNumber inPort = lspLocalLabelInfo.inPort();
- PortNumber outPort = lspLocalLabelInfo.outPort();
-
- // Push into device
- if ((inLabelId != null) && (inPort != null)) {
- installLocalLabelRule(deviceId, inLabelId, inPort, tunnel.tunnelId(), false,
- Long.valueOf(LabelType.IN_LABEL.value), Objective.Operation.REMOVE);
- }
-
- if ((outLabelId != null) && (outPort != null)) {
- installLocalLabelRule(deviceId, outLabelId, outPort, tunnel.tunnelId(), false,
- Long.valueOf(LabelType.OUT_LABEL.value), Objective.Operation.REMOVE);
- }
-
- // List is stored from egress to ingress. So, using IN label id to release.
- // Only one local label is assigned to device (destination node)
- // and that is used as OUT label for source node.
- // No need to release label for last node in the list from pool because label was not allocated to
- // ingress node (source node).
- if ((iterator.hasNext()) && (inLabelId != null)) {
- LabelResource labelRsc = new DefaultLabelResource(deviceId, inLabelId);
- release.put(deviceId, labelRsc);
- }
- }
- }
-
- // Release from label pool
- if (!release.isEmpty()) {
- labelRsrcService.releaseToDevicePool(release);
- }
-
- // Remove tunnel info only if tunnel consumer id is not saved.
- // If tunnel consumer id is saved, this tunnel info will be removed during releasing bandwidth.
- if (pceccTunnelInfo.tunnelConsumerId() == null) {
- pceStore.removeTunnelInfo(tunnel.tunnelId());
- }
- } else {
- log.error("Unable to find PCECC tunnel info in store for a tunnel {}.", tunnel.toString());
- }
- }
-
- // Install a rule for pushing local labels to the device which is specific to path.
- private synchronized void installLocalLabelRule(DeviceId deviceId, LabelResourceId labelId,
- PortNumber portNum, TunnelId tunnelId,
- Boolean isBos, Long labelType,
- Objective.Operation type) {
- checkNotNull(flowObjectiveService);
- checkNotNull(appId);
- TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
-
- selectorBuilder.matchMplsLabel(MplsLabel.mplsLabel(labelId.id().intValue()));
- selectorBuilder.matchInPort(portNum);
- selectorBuilder.matchTunnelId(Long.parseLong(tunnelId.id()));
- selectorBuilder.matchMplsBos(isBos);
- selectorBuilder.matchMetadata(labelType);
-
- TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
-
- ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder()
- .withSelector(selectorBuilder.build())
- .withTreatment(treatment)
- .withFlag(ForwardingObjective.Flag.VERSATILE)
- .fromApp(appId)
- .makePermanent();
-
- if (type.equals(Objective.Operation.ADD)) {
- flowObjectiveService.forward(deviceId, forwardingObjective.add());
- } else {
- flowObjectiveService.forward(deviceId, forwardingObjective.remove());
- }
- }
-}
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/LabelType.java b/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/LabelType.java
deleted file mode 100644
index 78e57f0..0000000
--- a/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/LabelType.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.
- */
-
-package org.onosproject.pce.pceservice;
-
-/**
- * Describes about Label type.
- */
-public enum LabelType {
- /**
- * Signifies in label id of a device.
- */
- OUT_LABEL(0),
-
- /**
- * Signifies out label id of a device.
- */
- IN_LABEL(1);
-
- int value;
-
- /**
- * Assign val with the value as the Label type.
- *
- * @param val Label type
- */
- LabelType(int val) {
- value = val;
- }
-
- /**
- * Returns value of Label type.
- *
- * @return label type
- */
- public byte type() {
- return (byte) value;
- }
-}
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceManager.java b/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceManager.java
index f777d4f..a4c2aa6 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceManager.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceManager.java
@@ -19,19 +19,11 @@
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
import java.util.Optional;
-import java.util.Map.Entry;
import java.util.Set;
-import java.util.concurrent.ScheduledExecutorService;
-
-import org.onlab.packet.Ethernet;
-import org.onlab.packet.IPv4;
-
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -39,18 +31,12 @@
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.packet.IpAddress;
-import org.onlab.packet.IpPrefix;
-import org.onlab.packet.TCP;
import org.onlab.util.Bandwidth;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
-import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
-import org.onosproject.incubator.net.resource.label.LabelResourceId;
-import org.onosproject.incubator.net.resource.label.LabelResourceService;
import org.onosproject.core.IdGenerator;
import org.onosproject.incubator.net.tunnel.DefaultTunnel;
import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
-import org.onosproject.incubator.net.tunnel.LabelStack;
import org.onosproject.incubator.net.tunnel.Tunnel;
import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
import org.onosproject.incubator.net.tunnel.TunnelEvent;
@@ -59,8 +45,6 @@
import org.onosproject.incubator.net.tunnel.TunnelName;
import org.onosproject.incubator.net.tunnel.TunnelService;
import org.onosproject.mastership.MastershipService;
-import org.onosproject.net.config.NetworkConfigEvent;
-import org.onosproject.net.config.NetworkConfigListener;
import org.onosproject.net.config.NetworkConfigService;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultAnnotations.Builder;
@@ -68,16 +52,10 @@
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
-import org.onosproject.net.device.DeviceEvent;
-import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.device.DeviceService;
-import org.onosproject.net.flowobjective.FlowObjectiveService;
-import org.onosproject.net.flowobjective.Objective;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
-import org.onosproject.net.link.LinkListener;
import org.onosproject.net.link.LinkEvent;
-import org.onosproject.net.link.LinkService;
import org.onosproject.net.MastershipRole;
import org.onosproject.pce.pceservice.constraint.CapabilityConstraint;
import org.onosproject.pce.pceservice.constraint.CapabilityConstraint.CapabilityType;
@@ -97,7 +75,6 @@
import org.onosproject.net.topology.TopologyService;
import org.onosproject.pce.pceservice.api.PceService;
import org.onosproject.pce.pcestore.PcePathInfo;
-import org.onosproject.pce.pcestore.PceccTunnelInfo;
import org.onosproject.pce.pcestore.api.PceStore;
import org.onosproject.pcep.api.DeviceCapability;
import org.onosproject.store.serializers.KryoNamespaces;
@@ -110,14 +87,10 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
-import static org.onosproject.incubator.net.tunnel.Tunnel.State.ACTIVE;
import static org.onosproject.incubator.net.tunnel.Tunnel.State.INIT;
-import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED;
import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE;
import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS;
import static org.onosproject.pce.pceservice.LspType.WITH_SIGNALLING;
-import static org.onosproject.pce.pceservice.LspType.SR_WITHOUT_SIGNALLING;
-import static org.onosproject.pce.pceservice.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
import static org.onosproject.pce.pceservice.PcepAnnotationKeys.BANDWIDTH;
import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LOCAL_LSP_ID;
import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LSP_SIG_TYPE;
@@ -127,11 +100,6 @@
import static org.onosproject.pce.pceservice.PcepAnnotationKeys.DELEGATE;
import static org.onosproject.pce.pceservice.PcepAnnotationKeys.COST_TYPE;
-import org.onosproject.net.packet.InboundPacket;
-import org.onosproject.net.packet.PacketContext;
-import org.onosproject.net.packet.PacketProcessor;
-import org.onosproject.net.packet.PacketService;
-
/**
* Implementation of PCE service.
*/
@@ -142,13 +110,10 @@
public static final long GLOBAL_LABEL_SPACE_MIN = 4097;
public static final long GLOBAL_LABEL_SPACE_MAX = 5121;
- private static final String DEVICE_NULL = "Device-cannot be null";
- private static final String LINK_NULL = "Link-cannot be null";
public static final String PCE_SERVICE_APP = "org.onosproject.pce";
private static final String LOCAL_LSP_ID_GEN_TOPIC = "pcep-local-lsp-id";
public static final String DEVICE_TYPE = "type";
public static final String L3_DEVICE = "L3";
- private static final int PREFIX_LENGTH = 32;
private static final String TUNNEL_CONSUMER_ID_GEN_TOPIC = "pcep-tunnel-consumer-id";
private IdGenerator tunnelConsumerIdGen;
@@ -156,16 +121,11 @@
private static final String LSRID = "lsrId";
private static final String TRUE = "true";
private static final String FALSE = "false";
- private static final String END_OF_SYNC_IP_PREFIX = "0.0.0.0/32";
public static final int PCEP_PORT = 4189;
private IdGenerator localLspIdIdGen;
protected DistributedSet<Short> localLspIdFreeList;
- // LSR-id and device-id mapping for checking capability if L3 device is not
- // having its capability
- private Map<String, DeviceId> lsrIdDeviceIdMap = new HashMap<>();
-
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
@@ -185,46 +145,24 @@
protected TunnelService tunnelService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected StorageService storageService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected PacketService packetService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceService deviceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected LinkService linkService;
+ protected StorageService storageService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected NetworkConfigService netCfgService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected LabelResourceAdminService labelRsrcAdminService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected LabelResourceService labelRsrcService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected FlowObjectiveService flowObjectiveService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected MastershipService mastershipService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected TopologyService topologyService;
private TunnelListener listener = new InnerTunnelListener();
- private DeviceListener deviceListener = new InternalDeviceListener();
- private LinkListener linkListener = new InternalLinkListener();
- private InternalConfigListener cfgListener = new InternalConfigListener();
- private BasicPceccHandler crHandler;
- private PceccSrTeBeHandler srTeHandler;
private ApplicationId appId;
- private final PcepPacketProcessor processor = new PcepPacketProcessor();
private final TopologyListener topologyListener = new InternalTopologyListener();
- private ScheduledExecutorService executor;
public static final int INITIAL_DELAY = 30;
public static final int PERIODIC_DELAY = 30;
@@ -238,17 +176,8 @@
@Activate
protected void activate() {
appId = coreService.registerApplication(PCE_SERVICE_APP);
- crHandler = BasicPceccHandler.getInstance();
- crHandler.initialize(labelRsrcService, flowObjectiveService, appId, pceStore);
-
- srTeHandler = PceccSrTeBeHandler.getInstance();
- srTeHandler.initialize(labelRsrcAdminService, labelRsrcService, flowObjectiveService, appId, pceStore,
- deviceService);
tunnelService.addListener(listener);
- deviceService.addListener(deviceListener);
- linkService.addListener(linkListener);
- netCfgService.addListener(cfgListener);
tunnelConsumerIdGen = coreService.getIdGenerator(TUNNEL_CONSUMER_ID_GEN_TOPIC);
localLspIdIdGen = coreService.getIdGenerator(LOCAL_LSP_ID_GEN_TOPIC);
@@ -259,24 +188,14 @@
.build()
.asDistributedSet();
- packetService.addProcessor(processor, PacketProcessor.director(4));
topologyService.addListener(topologyListener);
- // Reserve global node pool
- if (!srTeHandler.reserveGlobalPool(GLOBAL_LABEL_SPACE_MIN, GLOBAL_LABEL_SPACE_MAX)) {
- log.debug("Global node pool was already reserved.");
- }
-
log.info("Started");
}
@Deactivate
protected void deactivate() {
tunnelService.removeListener(listener);
- deviceService.removeListener(deviceListener);
- linkService.removeListener(linkListener);
- netCfgService.removeListener(cfgListener);
- packetService.removeProcessor(processor);
topologyService.removeListener(topologyListener);
log.info("Stopped");
}
@@ -401,16 +320,6 @@
annotationBuilder.set(DELEGATE, TRUE);
Path computedPath = computedPathSet.iterator().next();
- LabelStack labelStack = null;
-
- if (lspType == SR_WITHOUT_SIGNALLING) {
- labelStack = srTeHandler.computeLabelStack(computedPath);
- // Failed to form a label stack.
- if (labelStack == null) {
- pceStore.addFailedPathInfo(new PcePathInfo(src, dst, tunnelName, constraints, lspType));
- return false;
- }
- }
if (lspType != WITH_SIGNALLING) {
/*
@@ -423,7 +332,7 @@
// For SR-TE tunnels, call SR manager for label stack and put it inside tunnel.
Tunnel tunnel = new DefaultTunnel(null, srcEndPoint, dstEndPoint, MPLS, INIT, null, null,
TunnelName.tunnelName(tunnelName), computedPath,
- labelStack, annotationBuilder.build());
+ annotationBuilder.build());
// Allocate bandwidth.
TunnelConsumerId consumerId = null;
@@ -445,9 +354,8 @@
}
if (consumerId != null) {
- // Store tunnel consumer id in LSP-Label store.
- PceccTunnelInfo pceccTunnelInfo = new PceccTunnelInfo(null, consumerId);
- pceStore.addTunnelInfo(tunnelId, pceccTunnelInfo);
+ // Store tunnel consumer id in LSP store.
+ pceStore.addTunnelInfo(tunnelId, consumerId);
}
return true;
}
@@ -553,7 +461,6 @@
annotationBuilder.set(PCC_TUNNEL_ID, tunnel.annotations().value(PCC_TUNNEL_ID));
Path computedPath = computedPathSet.iterator().next();
- LabelStack labelStack = null;
TunnelConsumerId consumerId = null;
LspType lspType = LspType.valueOf(lspSigType);
long localLspId = 0;
@@ -564,19 +471,11 @@
*/
localLspId = getNextLocalLspId();
annotationBuilder.set(LOCAL_LSP_ID, String.valueOf(localLspId));
-
- if (lspType == SR_WITHOUT_SIGNALLING) {
- labelStack = srTeHandler.computeLabelStack(computedPath);
- // Failed to form a label stack.
- if (labelStack == null) {
- return false;
- }
- }
}
Tunnel updatedTunnel = new DefaultTunnel(null, tunnel.src(), tunnel.dst(), MPLS, INIT, null, null,
tunnel.tunnelName(), computedPath,
- labelStack, annotationBuilder.build());
+ annotationBuilder.build());
// Allocate shared bandwidth.
if (bwConstraintValue != 0) {
@@ -597,20 +496,8 @@
}
if (consumerId != null) {
- // Store tunnel consumer id in LSP-Label store.
- PceccTunnelInfo pceccTunnelInfo = new PceccTunnelInfo(null, consumerId);
- pceStore.addTunnelInfo(updatedTunnelId, pceccTunnelInfo);
- }
-
- // For CR cases, download labels and send update message.
- if (lspType == WITHOUT_SIGNALLING_AND_WITHOUT_SR) {
- Tunnel tunnelForlabelDownload = new DefaultTunnel(null, tunnel.src(), tunnel.dst(), MPLS, INIT, null,
- updatedTunnelId, tunnel.tunnelName(), computedPath,
- labelStack, annotationBuilder.build());
-
- if (!crHandler.allocateLabel(tunnelForlabelDownload)) {
- log.error("Unable to allocate labels for the tunnel {}.", tunnel.toString());
- }
+ // Store tunnel consumer id in LSP store.
+ pceStore.addTunnelInfo(updatedTunnelId, consumerId);
}
return true;
@@ -626,12 +513,6 @@
return false;
}
- LspType lspType = LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE));
- // Release basic PCECC labels.
- if (lspType == WITHOUT_SIGNALLING_AND_WITHOUT_SR) {
- crHandler.releaseLabel(tunnel);
- }
-
// 2. Call tunnel service.
return tunnelService.downTunnel(appId, tunnel.tunnelId());
}
@@ -845,19 +726,19 @@
}
}
+ ResourceConsumer tunnelConsumerId = pceStore.getTunnelInfo(tunnel.tunnelId());
+ if (tunnelConsumerId == null) {
+ //If bandwidth for old tunnel is not allocated i,e 0 then no need to release
+ log.debug("Bandwidth not allocated (0 bandwidth) for old LSP.");
+ return;
+ }
+
if (isLinkShared) {
releaseSharedBandwidth(newTunnel, tunnel);
return;
}
- PceccTunnelInfo tunnelInfo = pceStore.getTunnelInfo(tunnel.tunnelId());
- if (tunnelInfo == null || tunnelInfo.tunnelConsumerId() == null) {
- //If bandwidth for old tunnel is not allocated i,e 0 then no need to release
- return;
- }
- resourceService.release(tunnelInfo.tunnelConsumerId());
- return;
-
+ resourceService.release(tunnelConsumerId);
/*
* Note: Storing of tunnel consumer id is done by caller of bandwidth reservation function. So deleting tunnel
* consumer id should be done by caller of bandwidth releasing function. This will prevent ambiguities related
@@ -871,16 +752,15 @@
*/
private synchronized void releaseSharedBandwidth(Tunnel newTunnel, Tunnel oldTunnel) {
// 1. Release old tunnel's bandwidth.
- resourceService.release(pceStore.getTunnelInfo(oldTunnel.tunnelId()).tunnelConsumerId());
+ resourceService.release(pceStore.getTunnelInfo(oldTunnel.tunnelId()));
// 2. Release new tunnel's bandwidth, if new tunnel bandwidth is allocated
- PceccTunnelInfo tunnelInfo = pceStore.getTunnelInfo(newTunnel.tunnelId());
- if (tunnelInfo == null || tunnelInfo.tunnelConsumerId() == null) {
+ ResourceConsumer consumer = pceStore.getTunnelInfo(newTunnel.tunnelId());
+ if (consumer == null) {
//If bandwidth for new tunnel is not allocated i,e 0 then no need to allocate
return;
}
- ResourceConsumer consumer = tunnelInfo.tunnelConsumerId();
resourceService.release(consumer);
// 3. Allocate new tunnel's complete bandwidth.
@@ -895,245 +775,6 @@
}
}
- /**
- * Allocates node label to specific device.
- *
- * @param specificDevice device to which node label needs to be allocated
- */
- public void allocateNodeLabel(Device specificDevice) {
- checkNotNull(specificDevice, DEVICE_NULL);
-
- DeviceId deviceId = specificDevice.id();
-
- // Retrieve lsrId of a specific device
- if (specificDevice.annotations() == null) {
- log.debug("Device {} does not have annotations.", specificDevice.toString());
- return;
- }
-
- String lsrId = specificDevice.annotations().value(LSRID);
- if (lsrId == null) {
- log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString());
- return;
- }
-
- // Get capability config from netconfig
- DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class);
- if (cfg == null) {
- log.error("Unable to find corresponding capability for a lsrd {} from NetConfig.", lsrId);
- // Save info. When PCEP session is comes up then allocate node-label
- lsrIdDeviceIdMap.put(lsrId, specificDevice.id());
- return;
- }
-
- // Check whether device has SR-TE Capability
- if (cfg.labelStackCap()) {
- srTeHandler.allocateNodeLabel(deviceId, lsrId);
- }
- }
-
- /**
- * Releases node label of a specific device.
- *
- * @param specificDevice this device label and lsr-id information will be
- * released in other existing devices
- */
- public void releaseNodeLabel(Device specificDevice) {
- checkNotNull(specificDevice, DEVICE_NULL);
-
- DeviceId deviceId = specificDevice.id();
-
- // Retrieve lsrId of a specific device
- if (specificDevice.annotations() == null) {
- log.debug("Device {} does not have annotations.", specificDevice.toString());
- return;
- }
-
- String lsrId = specificDevice.annotations().value(LSRID);
- if (lsrId == null) {
- log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString());
- return;
- }
-
- // Get capability config from netconfig
- DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class);
- if (cfg == null) {
- log.error("Unable to find corresponding capabilty for a lsrd {} from NetConfig.", lsrId);
- return;
- }
-
- // Check whether device has SR-TE Capability
- if (cfg.labelStackCap()) {
- if (!srTeHandler.releaseNodeLabel(deviceId, lsrId)) {
- log.error("Unable to release node label for a device id {}.", deviceId.toString());
- }
- }
- }
-
- /**
- * Allocates adjacency label for a link.
- *
- * @param link link
- */
- public void allocateAdjacencyLabel(Link link) {
- checkNotNull(link, LINK_NULL);
-
- Device specificDevice = deviceService.getDevice(link.src().deviceId());
- DeviceId deviceId = specificDevice.id();
-
- // Retrieve lsrId of a specific device
- if (specificDevice.annotations() == null) {
- log.debug("Device {} does not have annotations.", specificDevice.toString());
- return;
- }
-
- String lsrId = specificDevice.annotations().value(LSRID);
- if (lsrId == null) {
- log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString());
- return;
- }
-
- // Get capability config from netconfig
- DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class);
- if (cfg == null) {
- log.error("Unable to find corresponding capabilty for a lsrd {} from NetConfig.", lsrId);
- // Save info. When PCEP session comes up then allocate adjacency
- // label
- if (lsrIdDeviceIdMap.get(lsrId) != null) {
- lsrIdDeviceIdMap.put(lsrId, specificDevice.id());
- }
- return;
- }
-
- // Check whether device has SR-TE Capability
- if (cfg.labelStackCap()) {
- srTeHandler.allocateAdjacencyLabel(link);
- }
-
- return;
- }
-
- /**
- * Releases allocated adjacency label of a link.
- *
- * @param link link
- */
- public void releaseAdjacencyLabel(Link link) {
- checkNotNull(link, LINK_NULL);
-
- Device specificDevice = deviceService.getDevice(link.src().deviceId());
- DeviceId deviceId = specificDevice.id();
-
- // Retrieve lsrId of a specific device
- if (specificDevice.annotations() == null) {
- log.debug("Device {} does not have annotations.", specificDevice.toString());
- return;
- }
-
- String lsrId = specificDevice.annotations().value(LSRID);
- if (lsrId == null) {
- log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString());
- return;
- }
-
- // Get capability config from netconfig
- DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class);
- if (cfg == null) {
- log.error("Unable to find corresponding capabilty for a lsrd {} from NetConfig.", lsrId);
- return;
- }
-
- // Check whether device has SR-TE Capability
- if (cfg.labelStackCap()) {
- if (!srTeHandler.releaseAdjacencyLabel(link)) {
- log.error("Unable to release adjacency labels for a link {}.", link.toString());
- return;
- }
- }
-
- return;
- }
-
- /*
- * Handle device events.
- */
- private class InternalDeviceListener implements DeviceListener {
- @Override
- public void event(DeviceEvent event) {
- Device specificDevice = (Device) event.subject();
- if (specificDevice == null) {
- log.error("Unable to find device from device event.");
- return;
- }
-
- switch (event.type()) {
-
- case DEVICE_ADDED:
- // Node-label allocation is being done during Label DB Sync.
- // So, when device is detected, no need to do node-label
- // allocation.
- String lsrId = specificDevice.annotations().value(LSRID);
- if (lsrId != null) {
- pceStore.addLsrIdDevice(lsrId, specificDevice.id());
-
- // Search in failed DB sync store. If found, trigger label DB sync.
- DeviceId pccDeviceId = DeviceId.deviceId(lsrId);
- if (pceStore.hasPccLsr(pccDeviceId)) {
- log.debug("Continue to perform label DB sync for device {}.", pccDeviceId.toString());
- syncLabelDb(pccDeviceId);
- pceStore.removePccLsr(pccDeviceId);
- }
- }
- break;
-
- case DEVICE_REMOVED:
- // Release node-label
- if (mastershipService.getLocalRole(specificDevice.id()) == MastershipRole.MASTER) {
- releaseNodeLabel(specificDevice);
- }
-
- if (specificDevice.annotations().value(LSRID) != null) {
- pceStore.removeLsrIdDevice(specificDevice.annotations().value(LSRID));
- }
-
- break;
-
- default:
- break;
- }
- }
- }
-
- /*
- * Handle link events.
- */
- private class InternalLinkListener implements LinkListener {
- @Override
- public void event(LinkEvent event) {
- Link link = (Link) event.subject();
-
- switch (event.type()) {
-
- case LINK_ADDED:
- // Allocate adjacency label
- if (mastershipService.getLocalRole(link.src().deviceId()) == MastershipRole.MASTER) {
- allocateAdjacencyLabel(link);
- }
- break;
-
- case LINK_REMOVED:
- // Release adjacency label
- if (mastershipService.getLocalRole(link.src().deviceId()) == MastershipRole.MASTER) {
- releaseAdjacencyLabel(link);
- }
- break;
-
- default:
- break;
- }
- }
- }
-
// Listens on tunnel events.
private class InnerTunnelListener implements TunnelListener {
@Override
@@ -1155,37 +796,16 @@
case TUNNEL_ADDED:
// Allocate bandwidth for non-initiated, delegated LSPs with non-zero bandwidth (learned LSPs).
String pceInit = tunnel.annotations().value(PCE_INIT);
- if (FALSE.equalsIgnoreCase(pceInit)
- && bwConstraintValue != 0) {
- reserveBandwidth(tunnel.path(), bwConstraintValue, null);
+ if (FALSE.equalsIgnoreCase(pceInit) && bwConstraintValue != 0) {
+ TunnelConsumerId consumerId = reserveBandwidth(tunnel.path(), bwConstraintValue, null);
+ if (consumerId != null) {
+ // Store tunnel consumer id in LSP store.
+ pceStore.addTunnelInfo(tunnel.tunnelId(), consumerId);
+ }
}
break;
case TUNNEL_UPDATED:
- // Allocate/send labels for basic PCECC tunnels.
- if ((tunnel.state() == ESTABLISHED) && (lspType == WITHOUT_SIGNALLING_AND_WITHOUT_SR)
- && (mastershipService.getLocalRole(tunnel.path().src().deviceId()) == MastershipRole.MASTER)) {
- if (!crHandler.allocateLabel(tunnel)) {
- log.error("Unable to allocate labels for a tunnel {}.", tunnel.toString());
- }
- }
-
- //In CR case, release labels when new tunnel for it is updated.
- if (lspType == WITHOUT_SIGNALLING_AND_WITHOUT_SR && tunnel.state() == ACTIVE
- && mastershipService.getLocalRole(tunnel.path().src().deviceId()) == MastershipRole.MASTER) {
- Collection<Tunnel> tunnels = tunnelService.queryTunnel(tunnel.src(), tunnel.dst());
-
- for (Tunnel t : tunnels) {
- if (tunnel.annotations().value(PLSP_ID).equals(t.annotations().value(PLSP_ID))
- && !tunnel.annotations().value(LOCAL_LSP_ID)
- .equals(t.annotations().value(LOCAL_LSP_ID))) {
- // Release basic PCECC labels.
- crHandler.releaseLabel(t);
- break;
- }
- }
- }
-
if (tunnel.state() == UNSTABLE) {
/*
* During LSP DB sync if PCC doesn't report LSP which was PCE initiated, it's state is turned into
@@ -1241,164 +861,6 @@
}
}
- private class InternalConfigListener implements NetworkConfigListener {
-
- @Override
- public void event(NetworkConfigEvent event) {
-
- if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED)
- && event.configClass().equals(DeviceCapability.class)) {
-
- DeviceId deviceIdLsrId = (DeviceId) event.subject();
- String lsrId = deviceIdLsrId.toString();
- DeviceId deviceId = lsrIdDeviceIdMap.get(lsrId);
- if (deviceId == null) {
- log.debug("Unable to find device id for a lsr-id {} from lsr-id and device-id map.", lsrId);
- return;
- }
-
- DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class);
- if (cfg == null) {
- log.error("Unable to find corresponding capabilty for a lsrd {}.", lsrId);
- return;
- }
-
- if (cfg.labelStackCap()) {
- if (mastershipService.getLocalRole(deviceId) == MastershipRole.MASTER) {
- // Allocate node-label
- srTeHandler.allocateNodeLabel(deviceId, lsrId);
-
- // Allocate adjacency label to links which are
- // originated from this specific device id
- Set<Link> links = linkService.getDeviceEgressLinks(deviceId);
- for (Link link : links) {
- if (!srTeHandler.allocateAdjacencyLabel(link)) {
- return;
- }
- }
- }
- }
-
- // Remove lsrId info from map
- lsrIdDeviceIdMap.remove(lsrId);
- }
- }
- }
-
- private boolean syncLabelDb(DeviceId deviceId) {
- checkNotNull(deviceId);
-
- DeviceId actualDevcieId = pceStore.getLsrIdDevice(deviceId.toString());
- if (actualDevcieId == null) {
- log.error("Device not available {}.", deviceId.toString());
- pceStore.addPccLsr(deviceId);
- return false;
- }
-
- Device specificDevice = deviceService.getDevice(actualDevcieId);
- if (specificDevice == null) {
- log.error("Unable to find device for specific device id {}.", actualDevcieId.toString());
- return false;
- }
-
- if (pceStore.getGlobalNodeLabel(actualDevcieId) != null) {
- Map<DeviceId, LabelResourceId> globalNodeLabelMap = pceStore.getGlobalNodeLabels();
-
- for (Entry<DeviceId, LabelResourceId> entry : globalNodeLabelMap.entrySet()) {
-
- // Convert from DeviceId to TunnelEndPoint
- Device srcDevice = deviceService.getDevice(entry.getKey());
-
- /*
- * If there is a slight difference in timing such that if device subsystem has removed the device but
- * PCE store still has it, just ignore such devices.
- */
- if (srcDevice == null) {
- continue;
- }
-
- String srcLsrId = srcDevice.annotations().value(LSRID);
- if (srcLsrId == null) {
- continue;
- }
-
- srTeHandler.advertiseNodeLabelRule(actualDevcieId,
- entry.getValue(),
- IpPrefix.valueOf(IpAddress.valueOf(srcLsrId), PREFIX_LENGTH),
- Objective.Operation.ADD, false);
- }
-
- Map<Link, LabelResourceId> adjLabelMap = pceStore.getAdjLabels();
- for (Entry<Link, LabelResourceId> entry : adjLabelMap.entrySet()) {
- if (entry.getKey().src().deviceId().equals(actualDevcieId)) {
- srTeHandler.installAdjLabelRule(actualDevcieId,
- entry.getValue(),
- entry.getKey().src().port(),
- entry.getKey().dst().port(),
- Objective.Operation.ADD);
- }
- }
- }
-
- srTeHandler.advertiseNodeLabelRule(actualDevcieId,
- LabelResourceId.labelResourceId(0),
- IpPrefix.valueOf(END_OF_SYNC_IP_PREFIX),
- Objective.Operation.ADD, true);
-
- log.debug("End of label DB sync for device {}", actualDevcieId);
-
- if (mastershipService.getLocalRole(specificDevice.id()) == MastershipRole.MASTER) {
- // Allocate node-label to this specific device.
- allocateNodeLabel(specificDevice);
-
- // Allocate adjacency label
- Set<Link> links = linkService.getDeviceEgressLinks(specificDevice.id());
- if (links != null) {
- for (Link link : links) {
- allocateAdjacencyLabel(link);
- }
- }
- }
-
- return true;
- }
-
- // Process the packet received.
- private class PcepPacketProcessor implements PacketProcessor {
- // Process the packet received and in our case initiates the label DB sync.
- @Override
- public void process(PacketContext context) {
- // Stop processing if the packet has been handled, since we
- // can't do any more to it.
- log.debug("Received trigger for label DB sync.");
- if (context.isHandled()) {
- return;
- }
-
- InboundPacket pkt = context.inPacket();
- if (pkt == null) {
- return;
- }
-
- Ethernet ethernet = pkt.parsed();
- if (ethernet == null || ethernet.getEtherType() != Ethernet.TYPE_IPV4) {
- return;
- }
-
- IPv4 ipPacket = (IPv4) ethernet.getPayload();
- if (ipPacket == null || ipPacket.getProtocol() != IPv4.PROTOCOL_TCP) {
- return;
- }
-
- TCP tcp = (TCP) ipPacket.getPayload();
- if (tcp == null || tcp.getDestinationPort() != PCEP_PORT) {
- return;
- }
-
- syncLabelDb(pkt.receivedFrom().deviceId());
- }
- }
-
//Computes path from tunnel store and also path failed to setup.
private void callForOptimization() {
//Recompute the LSPs which it was delegated [LSPs stored in PCE store (failed paths)]
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceccSrTeBeHandler.java b/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceccSrTeBeHandler.java
deleted file mode 100644
index 0a79716..0000000
--- a/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceccSrTeBeHandler.java
+++ /dev/null
@@ -1,526 +0,0 @@
-/*
- * 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.
- */
-package org.onosproject.pce.pceservice;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.HashSet;
-import java.util.List;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Set;
-
-import org.onlab.packet.IpAddress;
-import org.onlab.packet.IpPrefix;
-import org.onlab.packet.MplsLabel;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.incubator.net.resource.label.DefaultLabelResource;
-import org.onosproject.incubator.net.resource.label.LabelResource;
-import org.onosproject.incubator.net.resource.label.LabelResourceId;
-import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
-import org.onosproject.incubator.net.resource.label.LabelResourceService;
-import org.onosproject.incubator.net.tunnel.DefaultLabelStack;
-import org.onosproject.incubator.net.tunnel.LabelStack;
-import org.onosproject.net.device.DeviceService;
-import org.onosproject.net.Device;
-import org.onosproject.net.DeviceId;
-import org.onosproject.pce.pcestore.api.PceStore;
-import org.onosproject.net.Link;
-import org.onosproject.net.Path;
-import org.onosproject.net.PortNumber;
-import org.onosproject.net.flow.DefaultTrafficSelector;
-import org.onosproject.net.flow.DefaultTrafficTreatment;
-import org.onosproject.net.flow.TrafficSelector;
-import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.flowobjective.DefaultForwardingObjective;
-import org.onosproject.net.flowobjective.FlowObjectiveService;
-import org.onosproject.net.flowobjective.ForwardingObjective;
-import org.onosproject.net.flowobjective.Objective;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.Multimap;
-
-/**
- * PCE SR-BE and SR-TE functionality.
- * SR-BE: Each node (PCC) is allocated a node-SID (label) by the PCECC. The PCECC sends PCLabelUpd to
- * update the label map of each node to all the nodes in the domain.
- * SR-TE: apart from node-SID, Adj-SID is used where each adjacency is allocated an Adj-SID (label) by the PCECC.
- * The PCECC sends PCLabelUpd to update the label map of each Adj to the corresponding nodes in the domain.
- */
-public final class PceccSrTeBeHandler {
- private static final Logger log = LoggerFactory.getLogger(PceccSrTeBeHandler.class);
-
- private static final String LABEL_RESOURCE_ADMIN_SERVICE_NULL = "Label Resource Admin Service cannot be null";
- private static final String LABEL_RESOURCE_SERVICE_NULL = "Label Resource Service cannot be null";
- private static final String PCE_STORE_NULL = "PCE Store cannot be null";
- private static final String DEVICE_ID_NULL = "Device-Id cannot be null";
- private static final String LSR_ID_NULL = "LSR-Id cannot be null";
- private static final String LINK_NULL = "Link cannot be null";
- private static final String PATH_NULL = "Path cannot be null";
- private static final String LSR_ID = "lsrId";
- private static final int PREFIX_LENGTH = 32;
- private static PceccSrTeBeHandler srTeHandlerInstance = null;
- private LabelResourceAdminService labelRsrcAdminService;
- private LabelResourceService labelRsrcService;
- private FlowObjectiveService flowObjectiveService;
- private DeviceService deviceService;
- private PceStore pceStore;
- private ApplicationId appId;
-
- /**
- * Initializes default values.
- */
- private PceccSrTeBeHandler() {
- }
-
- /**
- * Returns single instance of this class.
- *
- * @return this class single instance
- */
- public static PceccSrTeBeHandler getInstance() {
- if (srTeHandlerInstance == null) {
- srTeHandlerInstance = new PceccSrTeBeHandler();
- }
- return srTeHandlerInstance;
- }
-
- /**
- * Initialization of label manager interfaces and pce store.
- *
- * @param labelRsrcAdminService label resource admin service
- * @param labelRsrcService label resource service
- * @param flowObjectiveService flow objective service to push device label information
- * @param appId application id
- * @param pceStore PCE label store
- * @param deviceService device service
- */
- public void initialize(LabelResourceAdminService labelRsrcAdminService, LabelResourceService labelRsrcService,
- FlowObjectiveService flowObjectiveService, ApplicationId appId, PceStore pceStore,
- DeviceService deviceService) {
- this.labelRsrcAdminService = labelRsrcAdminService;
- this.labelRsrcService = labelRsrcService;
- this.flowObjectiveService = flowObjectiveService;
- this.pceStore = pceStore;
- this.appId = appId;
- this.deviceService = deviceService;
- }
-
- /**
- * Reserves the global label pool.
- *
- * @param beginLabel minimum value of global label space
- * @param endLabel maximum value of global label space
- * @return success or failure
- */
- public boolean reserveGlobalPool(long beginLabel, long endLabel) {
- checkNotNull(labelRsrcAdminService, LABEL_RESOURCE_ADMIN_SERVICE_NULL);
- return labelRsrcAdminService.createGlobalPool(LabelResourceId.labelResourceId(beginLabel),
- LabelResourceId.labelResourceId(endLabel));
- }
-
- /**
- * Retrieve lsr-id from device annotation.
- *
- * @param deviceId specific device id from which lsr-id needs to be retrieved
- * @return lsr-id of a device
- */
- public String getLsrId(DeviceId deviceId) {
- checkNotNull(deviceId, DEVICE_ID_NULL);
- Device device = deviceService.getDevice(deviceId);
- if (device == null) {
- log.debug("Device is not available for device id {} in device service.", deviceId.toString());
- return null;
- }
-
- // Retrieve lsr-id from device
- if (device.annotations() == null) {
- log.debug("Device {} does not have annotation.", device.toString());
- return null;
- }
-
- String lsrId = device.annotations().value(LSR_ID);
- if (lsrId == null) {
- log.debug("The lsr-id of device {} is null.", device.toString());
- return null;
- }
- return lsrId;
- }
-
- /**
- * Allocates node label from global node label pool to specific device.
- * Configure this device with labels and lsrid mapping of all other devices and vice versa.
- *
- * @param specificDeviceId node label needs to be allocated to specific device
- * @param specificLsrId lsrid of specific device
- * @return success or failure
- */
- public boolean allocateNodeLabel(DeviceId specificDeviceId, String specificLsrId) {
- long applyNum = 1; // For each node only one node label
- LabelResourceId specificLabelId = null;
-
- checkNotNull(specificDeviceId, DEVICE_ID_NULL);
- checkNotNull(specificLsrId, LSR_ID_NULL);
- checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL);
- checkNotNull(pceStore, PCE_STORE_NULL);
-
- // Check whether node-label was already configured for this specific device.
- if (pceStore.getGlobalNodeLabel(specificDeviceId) != null) {
- log.debug("Node label was already configured for device {}.", specificDeviceId.toString());
- return false;
- }
-
- // The specificDeviceId is the new device and is not there in the pce store.
- // So, first generate its label and configure label and its lsr-id to it.
- Collection<LabelResource> result = labelRsrcService.applyFromGlobalPool(applyNum);
- if (result.size() > 0) {
- // Only one element (label-id) to retrieve
- Iterator<LabelResource> iterator = result.iterator();
- DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator.next();
- specificLabelId = defaultLabelResource.labelResourceId();
- if (specificLabelId == null) {
- log.error("Unable to retrieve global node label for a device id {}.", specificDeviceId.toString());
- return false;
- }
- } else {
- log.error("Unable to allocate global node label for a device id {}.", specificDeviceId.toString());
- return false;
- }
-
- // store it
- pceStore.addGlobalNodeLabel(specificDeviceId, specificLabelId);
-
- // Push its label information into specificDeviceId
- advertiseNodeLabelRule(specificDeviceId, specificLabelId,
- IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH),
- Objective.Operation.ADD, false);
-
- // Configure (node-label, lsr-id) mapping of each devices into specific device and vice versa.
- for (Map.Entry<DeviceId, LabelResourceId> element : pceStore.getGlobalNodeLabels().entrySet()) {
- DeviceId otherDevId = element.getKey();
- LabelResourceId otherLabelId = element.getValue();
-
- // Get lsr-id of a device
- String otherLsrId = getLsrId(otherDevId);
- if (otherLsrId == null) {
- log.error("The lsr-id of device id {} is null.", otherDevId.toString());
- releaseNodeLabel(specificDeviceId, specificLsrId);
- return false;
- }
-
- // Push to device
- // Push label information of specificDeviceId to otherDevId in list and vice versa.
- if (!otherDevId.equals(specificDeviceId)) {
- advertiseNodeLabelRule(otherDevId, specificLabelId,
- IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH),
- Objective.Operation.ADD, false);
-
- advertiseNodeLabelRule(specificDeviceId, otherLabelId,
- IpPrefix.valueOf(IpAddress.valueOf(otherLsrId), PREFIX_LENGTH),
- Objective.Operation.ADD, false);
- }
- }
-
- return true;
- }
-
- /**
- * Releases assigned node label of specific device from global node label pool and pce store.
- * and remove configured this node label from all other devices.
- *
- * @param specificDeviceId node label needs to be released for specific device
- * @param specificLsrId lsrid of specific device
- * @return success or failure
- */
- public boolean releaseNodeLabel(DeviceId specificDeviceId, String specificLsrId) {
- checkNotNull(specificDeviceId, DEVICE_ID_NULL);
- checkNotNull(specificLsrId, LSR_ID_NULL);
- checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL);
- checkNotNull(pceStore, PCE_STORE_NULL);
- boolean retValue = true;
-
- // Release node label entry of this specific device from all other devices
- // Retrieve node label of this specific device from store
- LabelResourceId labelId = pceStore.getGlobalNodeLabel(specificDeviceId);
- if (labelId == null) {
- log.error("Unable to retrieve label of a device id {} from store.", specificDeviceId.toString());
- return false;
- }
-
- // Go through all devices in the pce store and remove label entry from device
- for (Map.Entry<DeviceId, LabelResourceId> element : pceStore.getGlobalNodeLabels().entrySet()) {
- DeviceId otherDevId = element.getKey();
-
- // Remove this specific device label information from all other nodes except
- // this specific node where connection already lost.
- if (!specificDeviceId.equals(otherDevId)) {
- advertiseNodeLabelRule(otherDevId, labelId,
- IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH),
- Objective.Operation.REMOVE, false);
- }
- }
-
- // Release from label manager
- Set<LabelResourceId> release = new HashSet<>();
- release.add(labelId);
- if (!labelRsrcService.releaseToGlobalPool(release)) {
- log.error("Unable to release label id {} from label manager.", labelId.toString());
- retValue = false;
- }
-
- // Remove from store
- if (!pceStore.removeGlobalNodeLabel(specificDeviceId)) {
- log.error("Unable to remove global node label id {} from store.", labelId.toString());
- retValue = false;
- }
-
- return retValue;
- }
-
- /**
- * Allocates adjacency label to a link from local resource pool by a specific device id.
- *
- * @param link between devices
- * @return success or failure
- */
- public boolean allocateAdjacencyLabel(Link link) {
- long applyNum = 1; // Single label to each link.
- DeviceId srcDeviceId = link.src().deviceId();
- Collection<LabelResource> labelList;
-
- checkNotNull(link, LINK_NULL);
- checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL);
- checkNotNull(pceStore, PCE_STORE_NULL);
-
- // Checks whether adjacency label was already allocated
- LabelResourceId labelId = pceStore.getAdjLabel(link);
- if (labelId != null) {
- log.debug("Adjacency label {} was already allocated for a link {}.", labelId.toString(), link.toString());
- return false;
- }
-
- // Allocate adjacency label to a link from label manager.
- // Take label from source device pool to allocate.
- labelList = labelRsrcService.applyFromDevicePool(srcDeviceId, applyNum);
- if (labelList.size() <= 0) {
- log.error("Unable to allocate label to a device id {}.", srcDeviceId.toString());
- return false;
- }
-
- // Currently only one label to a device. So, no need to iterate through list
- Iterator<LabelResource> iterator = labelList.iterator();
- DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator.next();
- labelId = defaultLabelResource.labelResourceId();
- if (labelId == null) {
- log.error("Unable to allocate label to a device id {}.", srcDeviceId.toString());
- return false;
- }
- log.debug("Allocated adjacency label {} to a link {}.", labelId.toString(), link.toString());
-
- // Push adjacency label to device
- installAdjLabelRule(srcDeviceId, labelId, link.src().port(), link.dst().port(), Objective.Operation.ADD);
-
- // Save in store
- pceStore.addAdjLabel(link, labelId);
- return true;
- }
-
- /**
- * Releases unused adjacency labels from device pools.
- *
- * @param link between devices
- * @return success or failure
- */
- public boolean releaseAdjacencyLabel(Link link) {
- checkNotNull(link, LINK_NULL);
- checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL);
- checkNotNull(pceStore, PCE_STORE_NULL);
- boolean retValue = true;
-
- // Retrieve link label from store
- LabelResourceId labelId = pceStore.getAdjLabel(link);
- if (labelId == null) {
- log.error("Unabel to retrieve label for a link {} from store.", link.toString());
- return false;
- }
-
- // Device
- DeviceId srcDeviceId = link.src().deviceId();
-
- // Release adjacency label from device
- installAdjLabelRule(srcDeviceId, labelId, link.src().port(), link.dst().port(), Objective.Operation.REMOVE);
-
- // Release link label from label manager
- Multimap<DeviceId, LabelResource> release = ArrayListMultimap.create();
- DefaultLabelResource defaultLabelResource = new DefaultLabelResource(srcDeviceId, labelId);
- release.put(srcDeviceId, defaultLabelResource);
- if (!labelRsrcService.releaseToDevicePool(release)) {
- log.error("Unable to release label id {} from label manager.", labelId.toString());
- retValue = false;
- }
-
- // Remove adjacency label from store
- if (!pceStore.removeAdjLabel(link)) {
- log.error("Unable to remove adjacency label id {} from store.", labelId.toString());
- retValue = false;
- }
- return retValue;
- }
-
- /**
- * Computes label stack for a path.
- *
- * @param path lsp path
- * @return label stack
- */
- public LabelStack computeLabelStack(Path path) {
- checkNotNull(path, PATH_NULL);
- // Label stack is linked list to make labels in order.
- List<LabelResourceId> labelStack = new LinkedList<>();
- List<Link> linkList = path.links();
- if ((linkList != null) && (linkList.size() > 0)) {
- // Path: [x] ---- [y] ---- [z]
- // For other than last link, add only source[x] device label.
- // For the last link, add both source[y] and destination[z] device labels.
- // For all links add adjacency label
- Link link = null;
- LabelResourceId nodeLabelId = null;
- LabelResourceId adjLabelId = null;
- DeviceId deviceId = null;
- for (Iterator<Link> iterator = linkList.iterator(); iterator.hasNext();) {
- link = iterator.next();
- // Add adjacency label for this link
- adjLabelId = pceStore.getAdjLabel(link);
- if (adjLabelId == null) {
- log.error("Adjacency label id is null for a link {}.", link.toString());
- return null;
- }
- labelStack.add(adjLabelId);
-
- deviceId = link.dst().deviceId();
- nodeLabelId = pceStore.getGlobalNodeLabel(deviceId);
- if (nodeLabelId == null) {
- log.error("Unable to find node label for a device id {} in store.", deviceId.toString());
- return null;
- }
- labelStack.add(nodeLabelId);
- }
- } else {
- log.debug("Empty link in path.");
- return null;
- }
- return new DefaultLabelStack(labelStack);
- }
-
- /**
- * Install a rule for pushing unique global labels to the device.
- *
- * @param deviceId device to which flow should be pushed
- * @param labelId label for the device
- * @param type type of operation
- */
- private void installNodeLabelRule(DeviceId deviceId, LabelResourceId labelId, Objective.Operation type) {
- checkNotNull(flowObjectiveService);
- checkNotNull(appId);
- TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
-
- selectorBuilder.matchMplsLabel(MplsLabel.mplsLabel(labelId.id().intValue()));
-
- TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
-
- ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder()
- .withSelector(selectorBuilder.build()).withTreatment(treatment)
- .withFlag(ForwardingObjective.Flag.VERSATILE).fromApp(appId).makePermanent();
-
- if (type.equals(Objective.Operation.ADD)) {
-
- flowObjectiveService.forward(deviceId, forwardingObjective.add());
- } else {
- flowObjectiveService.forward(deviceId, forwardingObjective.remove());
- }
- }
-
- /**
- * Install a rule for pushing node labels to the device of other nodes.
- *
- * @param deviceId device to which flow should be pushed
- * @param labelId label for the device
- * @param ipPrefix device for which label is pushed
- * @param type type of operation
- * @param bBos is this the end of sync push
- */
- public void advertiseNodeLabelRule(DeviceId deviceId, LabelResourceId labelId, IpPrefix ipPrefix,
- Objective.Operation type, boolean bBos) {
- checkNotNull(flowObjectiveService);
- checkNotNull(appId);
- TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
-
- selectorBuilder.matchMplsLabel(MplsLabel.mplsLabel(labelId.id().intValue()));
- selectorBuilder.matchIPSrc(ipPrefix);
-
- if (bBos) {
- selectorBuilder.matchMplsBos(bBos);
- }
-
- TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
-
- ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder()
- .withSelector(selectorBuilder.build()).withTreatment(treatment)
- .withFlag(ForwardingObjective.Flag.VERSATILE).fromApp(appId).makePermanent();
-
- if (type.equals(Objective.Operation.ADD)) {
- flowObjectiveService.forward(deviceId, forwardingObjective.add());
- } else {
- flowObjectiveService.forward(deviceId, forwardingObjective.remove());
- }
- }
-
- /**
- * Install a rule for pushing Adjacency labels to the device.
- *
- * @param deviceId device to which flow should be pushed
- * @param labelId label for the adjacency
- * @param srcPortNum local port of the adjacency
- * @param dstPortNum remote port of the adjacency
- * @param type type of operation
- */
- public void installAdjLabelRule(DeviceId deviceId, LabelResourceId labelId, PortNumber srcPortNum,
- PortNumber dstPortNum, Objective.Operation type) {
- checkNotNull(flowObjectiveService);
- checkNotNull(appId);
- TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
-
- selectorBuilder.matchMplsLabel(MplsLabel.mplsLabel(labelId.id().intValue()));
- selectorBuilder.matchIPSrc(IpPrefix.valueOf((int) srcPortNum.toLong(), 32));
- selectorBuilder.matchIPDst(IpPrefix.valueOf((int) dstPortNum.toLong(), 32));
-
- TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
-
- ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder()
- .withSelector(selectorBuilder.build()).withTreatment(treatment)
- .withFlag(ForwardingObjective.Flag.VERSATILE).fromApp(appId).makePermanent();
-
- if (type.equals(Objective.Operation.ADD)) {
- flowObjectiveService.forward(deviceId, forwardingObjective.add());
- } else {
- flowObjectiveService.forward(deviceId, forwardingObjective.remove());
- }
- }
-}