Avantika-Huawei
Committed by Gerrit Code Review

Move PCE label handling from APP to protocol.

Change-Id: I26ae21b27ac2dc9ae3302030f6860e0e371c342c
Showing 60 changed files with 5063 additions and 3418 deletions
/*
* 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());
}
}
}
......@@ -19,19 +19,11 @@ import static com.google.common.base.Preconditions.checkNotNull;
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.Reference;
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.TunnelListener;
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.Device;
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.TopologyListener;
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 org.slf4j.LoggerFactory;
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.PCC_TUNNEL_ID;
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 class PceManager implements PceService {
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 @@ public class PceManager implements PceService {
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 @@ public class PceManager implements PceService {
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 @@ public class PceManager implements PceService {
@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 @@ public class PceManager implements PceService {
.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 @@ public class PceManager implements PceService {
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 @@ public class PceManager implements PceService {
// 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 @@ public class PceManager implements PceService {
}
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 @@ public class PceManager implements PceService {
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 @@ public class PceManager implements PceService {
*/
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 @@ public class PceManager implements PceService {
}
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 @@ public class PceManager implements PceService {
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 @@ public class PceManager implements PceService {
}
}
if (isLinkShared) {
releaseSharedBandwidth(newTunnel, tunnel);
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;
}
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
if (isLinkShared) {
releaseSharedBandwidth(newTunnel, tunnel);
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 @@ public class PceManager implements PceService {
*/
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 @@ public class PceManager implements PceService {
}
}
/**
* 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 @@ public class PceManager implements PceService {
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);
}
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());
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);
}
}
//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;
}
}
}
case TUNNEL_UPDATED:
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 @@ public class PceManager implements PceService {
}
}
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)]
......
......@@ -19,9 +19,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.ImmutableSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -34,18 +31,13 @@ import org.apache.felix.scr.annotations.Service;
import org.onlab.util.KryoNamespace;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.incubator.net.resource.label.LabelResource;
import org.onosproject.incubator.net.resource.label.LabelResourceId;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.resource.ResourceConsumer;
import org.onosproject.pce.pceservice.constraint.CapabilityConstraint;
import org.onosproject.pce.pceservice.constraint.CostConstraint;
import org.onosproject.pce.pceservice.TunnelConsumerId;
import org.onosproject.pce.pceservice.LspType;
import org.onosproject.pce.pceservice.constraint.SharedBandwidthConstraint;
import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
import org.onosproject.pce.pcestore.api.PceStore;
import org.onosproject.store.serializers.KryoNamespaces;
import org.onosproject.store.service.ConsistentMap;
......@@ -62,42 +54,21 @@ import org.slf4j.LoggerFactory;
@Component(immediate = true)
@Service
public class DistributedPceStore implements PceStore {
private static final String DEVICE_ID_NULL = "Device ID cannot be null";
private static final String DEVICE_LABEL_STORE_INFO_NULL = "Device Label Store cannot be null";
private static final String LABEL_RESOURCE_ID_NULL = "Label Resource Id cannot be null";
private static final String LABEL_RESOURCE_LIST_NULL = "Label Resource List cannot be null";
private static final String LABEL_RESOURCE_NULL = "Label Resource cannot be null";
private static final String LINK_NULL = "LINK cannot be null";
private static final String LSP_LOCAL_LABEL_INFO_NULL = "LSP Local Label Info cannot be null";
private static final String PATH_INFO_NULL = "Path Info cannot be null";
private static final String PCECC_TUNNEL_INFO_NULL = "PCECC Tunnel Info cannot be null";
private static final String TUNNEL_ID_NULL = "Tunnel Id cannot be null";
private static final String TUNNEL_CONSUMER_ID_NULL = "Tunnel consumer Id cannot be null";
private final Logger log = LoggerFactory.getLogger(getClass());
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected StorageService storageService;
// Mapping device with global node label
private ConsistentMap<DeviceId, LabelResourceId> globalNodeLabelMap;
// Mapping link with adjacency label
private ConsistentMap<Link, LabelResourceId> adjLabelMap;
// Mapping tunnel with device local info with tunnel consumer id
private ConsistentMap<TunnelId, PceccTunnelInfo> tunnelInfoMap;
private ConsistentMap<TunnelId, ResourceConsumer> tunnelInfoMap;
// List of Failed path info
private DistributedSet<PcePathInfo> failedPathSet;
// Locally maintain LSRID to device id mapping for better performance.
private Map<String, DeviceId> lsrIdDeviceIdMap = new HashMap<>();
// List of PCC LSR ids whose BGP device information was not available to perform
// label db sync.
private HashSet<DeviceId> pendinglabelDbSyncPccMap = new HashSet();
private static final Serializer SERIALIZER = Serializer
.using(new KryoNamespace.Builder().register(KryoNamespaces.API)
.register(PcePathInfo.class)
......@@ -112,36 +83,13 @@ public class DistributedPceStore implements PceStore {
@Activate
protected void activate() {
globalNodeLabelMap = storageService.<DeviceId, LabelResourceId>consistentMapBuilder()
.withName("onos-pce-globalnodelabelmap")
.withSerializer(Serializer.using(
new KryoNamespace.Builder()
.register(KryoNamespaces.API)
.register(LabelResourceId.class)
.build()))
.build();
adjLabelMap = storageService.<Link, LabelResourceId>consistentMapBuilder()
.withName("onos-pce-adjlabelmap")
.withSerializer(Serializer.using(
new KryoNamespace.Builder()
.register(KryoNamespaces.API)
.register(Link.class,
LabelResource.class,
LabelResourceId.class)
.build()))
.build();
tunnelInfoMap = storageService.<TunnelId, PceccTunnelInfo>consistentMapBuilder()
tunnelInfoMap = storageService.<TunnelId, ResourceConsumer>consistentMapBuilder()
.withName("onos-pce-tunnelinfomap")
.withSerializer(Serializer.using(
new KryoNamespace.Builder()
.register(KryoNamespaces.API)
.register(TunnelId.class,
PceccTunnelInfo.class,
DefaultLspLocalLabelInfo.class,
TunnelConsumerId.class,
LabelResourceId.class)
TunnelConsumerId.class)
.build()))
.build();
......@@ -160,18 +108,6 @@ public class DistributedPceStore implements PceStore {
}
@Override
public boolean existsGlobalNodeLabel(DeviceId id) {
checkNotNull(id, DEVICE_ID_NULL);
return globalNodeLabelMap.containsKey(id);
}
@Override
public boolean existsAdjLabel(Link link) {
checkNotNull(link, LINK_NULL);
return adjLabelMap.containsKey(link);
}
@Override
public boolean existsTunnelInfo(TunnelId tunnelId) {
checkNotNull(tunnelId, TUNNEL_ID_NULL);
return tunnelInfoMap.containsKey(tunnelId);
......@@ -184,16 +120,6 @@ public class DistributedPceStore implements PceStore {
}
@Override
public int getGlobalNodeLabelCount() {
return globalNodeLabelMap.size();
}
@Override
public int getAdjLabelCount() {
return adjLabelMap.size();
}
@Override
public int getTunnelInfoCount() {
return tunnelInfoMap.size();
}
......@@ -204,21 +130,9 @@ public class DistributedPceStore implements PceStore {
}
@Override
public Map<DeviceId, LabelResourceId> getGlobalNodeLabels() {
return globalNodeLabelMap.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue().value()));
}
@Override
public Map<Link, LabelResourceId> getAdjLabels() {
return adjLabelMap.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue().value()));
}
@Override
public Map<TunnelId, PceccTunnelInfo> getTunnelInfos() {
public Map<TunnelId, ResourceConsumer> getTunnelInfos() {
return tunnelInfoMap.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> (PceccTunnelInfo) e.getValue().value()));
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().value()));
}
@Override
......@@ -227,45 +141,17 @@ public class DistributedPceStore implements PceStore {
}
@Override
public LabelResourceId getGlobalNodeLabel(DeviceId id) {
checkNotNull(id, DEVICE_ID_NULL);
return globalNodeLabelMap.get(id) == null ? null : globalNodeLabelMap.get(id).value();
}
@Override
public LabelResourceId getAdjLabel(Link link) {
checkNotNull(link, LINK_NULL);
return adjLabelMap.get(link) == null ? null : adjLabelMap.get(link).value();
}
@Override
public PceccTunnelInfo getTunnelInfo(TunnelId tunnelId) {
public ResourceConsumer getTunnelInfo(TunnelId tunnelId) {
checkNotNull(tunnelId, TUNNEL_ID_NULL);
return tunnelInfoMap.get(tunnelId) == null ? null : tunnelInfoMap.get(tunnelId).value();
}
@Override
public void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId) {
checkNotNull(deviceId, DEVICE_ID_NULL);
checkNotNull(labelId, LABEL_RESOURCE_ID_NULL);
globalNodeLabelMap.put(deviceId, labelId);
}
@Override
public void addAdjLabel(Link link, LabelResourceId labelId) {
checkNotNull(link, LINK_NULL);
checkNotNull(labelId, LABEL_RESOURCE_ID_NULL);
adjLabelMap.put(link, labelId);
}
@Override
public void addTunnelInfo(TunnelId tunnelId, PceccTunnelInfo pceccTunnelInfo) {
public void addTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId) {
checkNotNull(tunnelId, TUNNEL_ID_NULL);
checkNotNull(pceccTunnelInfo, PCECC_TUNNEL_INFO_NULL);
checkNotNull(tunnelConsumerId, PCECC_TUNNEL_INFO_NULL);
tunnelInfoMap.put(tunnelId, pceccTunnelInfo);
tunnelInfoMap.put(tunnelId, tunnelConsumerId);
}
@Override
......@@ -275,62 +161,6 @@ public class DistributedPceStore implements PceStore {
}
@Override
public boolean updateTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList) {
checkNotNull(tunnelId, TUNNEL_ID_NULL);
checkNotNull(lspLocalLabelInfoList, LSP_LOCAL_LABEL_INFO_NULL);
if (!tunnelInfoMap.containsKey((tunnelId))) {
log.debug("Tunnel info does not exist whose tunnel id is {}.", tunnelId.toString());
return false;
}
PceccTunnelInfo tunnelInfo = tunnelInfoMap.get(tunnelId).value();
tunnelInfo.lspLocalLabelInfoList(lspLocalLabelInfoList);
tunnelInfoMap.put(tunnelId, tunnelInfo);
return true;
}
@Override
public boolean updateTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId) {
checkNotNull(tunnelId, TUNNEL_ID_NULL);
checkNotNull(tunnelConsumerId, TUNNEL_CONSUMER_ID_NULL);
if (!tunnelInfoMap.containsKey((tunnelId))) {
log.debug("Tunnel info does not exist whose tunnel id is {}.", tunnelId.toString());
return false;
}
PceccTunnelInfo tunnelInfo = tunnelInfoMap.get(tunnelId).value();
tunnelInfo.tunnelConsumerId(tunnelConsumerId);
tunnelInfoMap.put(tunnelId, tunnelInfo);
return true;
}
@Override
public boolean removeGlobalNodeLabel(DeviceId id) {
checkNotNull(id, DEVICE_ID_NULL);
if (globalNodeLabelMap.remove(id) == null) {
log.error("SR-TE node label deletion for device {} has failed.", id.toString());
return false;
}
return true;
}
@Override
public boolean removeAdjLabel(Link link) {
checkNotNull(link, LINK_NULL);
if (adjLabelMap.remove(link) == null) {
log.error("Adjacency label deletion for link {} hash failed.", link.toString());
return false;
}
return true;
}
@Override
public boolean removeTunnelInfo(TunnelId tunnelId) {
checkNotNull(tunnelId, TUNNEL_ID_NULL);
......@@ -351,50 +181,4 @@ public class DistributedPceStore implements PceStore {
}
return true;
}
@Override
public boolean addLsrIdDevice(String lsrId, DeviceId deviceId) {
checkNotNull(lsrId);
checkNotNull(deviceId);
lsrIdDeviceIdMap.put(lsrId, deviceId);
return true;
}
@Override
public boolean removeLsrIdDevice(String lsrId) {
checkNotNull(lsrId);
lsrIdDeviceIdMap.remove(lsrId);
return true;
}
@Override
public DeviceId getLsrIdDevice(String lsrId) {
checkNotNull(lsrId);
return lsrIdDeviceIdMap.get(lsrId);
}
@Override
public boolean addPccLsr(DeviceId lsrId) {
checkNotNull(lsrId);
pendinglabelDbSyncPccMap.add(lsrId);
return true;
}
@Override
public boolean removePccLsr(DeviceId lsrId) {
checkNotNull(lsrId);
pendinglabelDbSyncPccMap.remove(lsrId);
return true;
}
@Override
public boolean hasPccLsr(DeviceId lsrId) {
checkNotNull(lsrId);
return pendinglabelDbSyncPccMap.contains(lsrId);
}
}
......
/*
* 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.pcestore;
import com.google.common.base.MoreObjects;
import java.util.Objects;
import java.util.List;
import org.onosproject.net.resource.ResourceConsumer;
import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
/**
* PCECC tunnel information is used to store
* list of links label information of a path containing IN, OUT label and destination port of a link
* to release label allocation in devices.
* Also storing resource consumer id to release bandwdith of a tunnel.
* The first entry is created with TunnelId and resource consumer id,
* later this entry may be updated to store label information on basic PCECC case.
*/
public final class PceccTunnelInfo {
private List<LspLocalLabelInfo> lspLocalLabelInfoList;
private ResourceConsumer tunnelConsumerId;
/**
* Initialization of member variables.
*
* @param lspLocalLabelInfoList list of devices local label info
* @param tunnelConsumerId tunnel consumer id
*/
public PceccTunnelInfo(List<LspLocalLabelInfo> lspLocalLabelInfoList,
ResourceConsumer tunnelConsumerId) {
this.lspLocalLabelInfoList = lspLocalLabelInfoList;
this.tunnelConsumerId = tunnelConsumerId;
}
/**
* Initialization for serialization.
*/
public PceccTunnelInfo() {
this.lspLocalLabelInfoList = null;
this.tunnelConsumerId = null;
}
/**
* Retrieves list of devices local label info.
*
* @return list of devices local label info
*/
public List<LspLocalLabelInfo> lspLocalLabelInfoList() {
return this.lspLocalLabelInfoList;
}
/**
* Retrieves tunnel consumer id.
*
* @return tunnel consumer id
*/
public ResourceConsumer tunnelConsumerId() {
return this.tunnelConsumerId;
}
/**
* Sets list of local label info of a path.
*
* @param lspLocalLabelInfoList list of devices local label info
*/
public void lspLocalLabelInfoList(List<LspLocalLabelInfo> lspLocalLabelInfoList) {
this.lspLocalLabelInfoList = lspLocalLabelInfoList;
}
/**
* Sets tunnel consumer id.
*
* @param id tunnel consumer id
*/
public void tunnelConsumerId(ResourceConsumer id) {
this.tunnelConsumerId = id;
}
@Override
public int hashCode() {
return Objects.hash(lspLocalLabelInfoList, tunnelConsumerId);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof PceccTunnelInfo) {
final PceccTunnelInfo other = (PceccTunnelInfo) obj;
return Objects.equals(this.lspLocalLabelInfoList, other.lspLocalLabelInfoList) &&
Objects.equals(this.tunnelConsumerId, other.tunnelConsumerId);
}
return false;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("DeviceLabelInfoList", lspLocalLabelInfoList)
.add("TunnelConsumerId", tunnelConsumerId)
.toString();
}
}
......@@ -15,14 +15,8 @@
*/
package org.onosproject.pce.pcestore.api;
import java.util.List;
import org.onosproject.incubator.net.resource.label.LabelResourceId;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.resource.ResourceConsumer;
import org.onosproject.pce.pcestore.PceccTunnelInfo;
import org.onosproject.pce.pcestore.PcePathInfo;
import java.util.Map;
......@@ -32,22 +26,6 @@ import java.util.Map;
*/
public interface PceStore {
/**
* Checks whether device id is present in global node label store.
*
* @param id device id
* @return success of failure
*/
boolean existsGlobalNodeLabel(DeviceId id);
/**
* Checks whether link is present in adjacency label store.
*
* @param link link between devices
* @return success of failure
*/
boolean existsAdjLabel(Link link);
/**
* Checks whether tunnel id is present in tunnel info store.
*
* @param tunnelId tunnel id
......@@ -64,20 +42,6 @@ public interface PceStore {
boolean existsFailedPathInfo(PcePathInfo failedPathInfo);
/**
* Retrieves the node label count.
*
* @return node label count
*/
int getGlobalNodeLabelCount();
/**
* Retrieves the adjacency label count.
*
* @return adjacency label count
*/
int getAdjLabelCount();
/**
* Retrieves the tunnel info count.
*
* @return tunnel info count
......@@ -92,25 +56,11 @@ public interface PceStore {
int getFailedPathInfoCount();
/**
* Retrieves device id and label pairs collection from global node label store.
*
* @return collection of device id and label pairs
*/
Map<DeviceId, LabelResourceId> getGlobalNodeLabels();
/**
* Retrieves link and label pairs collection from adjacency label store.
*
* @return collection of link and label pairs
*/
Map<Link, LabelResourceId> getAdjLabels();
/**
* Retrieves tunnel id and pcecc tunnel info pairs collection from tunnel info store.
*
* @return collection of tunnel id and pcecc tunnel info pairs
* @return collection of tunnel id and resource consumer pairs
*/
Map<TunnelId, PceccTunnelInfo> getTunnelInfos();
Map<TunnelId, ResourceConsumer> getTunnelInfos();
/**
* Retrieves path info collection from failed path info store.
......@@ -120,52 +70,20 @@ public interface PceStore {
Iterable<PcePathInfo> getFailedPathInfos();
/**
* Retrieves node label for specified device id.
*
* @param id device id
* @return node label
*/
LabelResourceId getGlobalNodeLabel(DeviceId id);
/**
* Retrieves adjacency label for specified link.
*
* @param link between devices
* @return adjacency label
*/
LabelResourceId getAdjLabel(Link link);
/**
* Retrieves local label info with tunnel consumer id from tunnel info store.
*
* @param tunnelId tunnel id
* @return pcecc tunnel info
*/
PceccTunnelInfo getTunnelInfo(TunnelId tunnelId);
/**
* Stores node label into global node label store.
*
* @param deviceId device id
* @param labelId node label id
*/
void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId);
/**
* Stores adjacency label into adjacency label store.
*
* @param link link between nodes
* @param labelId link label id
* @return resource consumer
*/
void addAdjLabel(Link link, LabelResourceId labelId);
ResourceConsumer getTunnelInfo(TunnelId tunnelId);
/**
* Stores local label info with tunnel consumer id into tunnel info store for specified tunnel id.
*
* @param tunnelId tunnel id
* @param pceccTunnelInfo local label info
* @param tunnelConsumerId tunnel consumer id
*/
void addTunnelInfo(TunnelId tunnelId, PceccTunnelInfo pceccTunnelInfo);
void addTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId);
/**
* Stores path information into failed path info store.
......@@ -175,41 +93,6 @@ public interface PceStore {
void addFailedPathInfo(PcePathInfo failedPathInfo);
/**
* Updates local label info. The first entry is created with TunnelId and TunnelConsumerId.
* Later this entry may be updated to store label information if it is basic PCECC case.
*
* @param tunnelId tunnel id
* @param lspLocalLabelInfoList list of local labels
* @return success or failure
*/
boolean updateTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList);
/**
* Updates tunnel info map with tunnel consumer id.
*
* @param tunnelId tunnel id
* @param tunnelConsumerId tunnel consumer id
* @return success or failure
*/
boolean updateTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId);
/**
* Removes device label from global node label store for specified device id.
*
* @param id device id
* @return success or failure
*/
boolean removeGlobalNodeLabel(DeviceId id);
/**
* Removes adjacency label from adjacency label store for specified link information.
*
* @param link between nodes
* @return success or failure
*/
boolean removeAdjLabel(Link link);
/**
* Removes local label info with tunnel consumer id from tunnel info store for specified tunnel id.
*
* @param tunnelId tunnel id
......@@ -224,54 +107,4 @@ public interface PceStore {
* @return success or failure
*/
boolean removeFailedPathInfo(PcePathInfo failedPathInfo);
/**
* Adds lsrid to device id mapping.
*
* @param lsrId lsrId of the device
* @param deviceId device id
* @return success or failure
*/
boolean addLsrIdDevice(String lsrId, DeviceId deviceId);
/**
* Removes lsrid to device id mapping.
*
* @param lsrId lsrId of the device
* @return success or failure
*/
boolean removeLsrIdDevice(String lsrId);
/**
* Gets lsrid to device id mapping.
*
* @param lsrId lsrId of the device
* @return device id of the lsrId
*/
DeviceId getLsrIdDevice(String lsrId);
/**
* Adds lsrId of the PCC in form of device id for the PCC for which sync is pending due to non-availability of BGP.
* device.
*
* @param lsrId LSR id of the PCC in form of device id
* @return success or failure
*/
public boolean addPccLsr(DeviceId lsrId);
/**
* Removes lsrId of the PCC in form of device id for the PCC for which pending sync is done.
*
* @param lsrId LSR id of the PCC in form of device id
* @return success or failure
*/
public boolean removePccLsr(DeviceId lsrId);
/**
* Gets lsrId of the PCC in form of device id.
*
* @param lsrId LSR id of the PCC in form of device id
* @return success or failure
*/
public boolean hasPccLsr(DeviceId lsrId);
}
......
package org.onosproject.pce.pceservice;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.core.Is.is;
import static org.onlab.graph.GraphPathSearch.ALL_PATHS;
import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED;
import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE;
import static org.onosproject.net.Link.State.ACTIVE;
import static org.onosproject.net.Link.Type.DIRECT;
import static org.onosproject.net.MastershipRole.MASTER;
import static org.onosproject.net.resource.Resources.continuous;
import static org.onosproject.pce.pceservice.LspType.SR_WITHOUT_SIGNALLING;
......@@ -22,13 +18,11 @@ import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE1;
import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE2;
import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE3;
import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE4;
import static org.onosproject.pce.pceservice.PceManager.PCEP_PORT;
import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LOCAL_LSP_ID;
import static org.onosproject.pce.pceservice.PcepAnnotationKeys.PLSP_ID;
import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.COST;
import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.TE_COST;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
......@@ -44,9 +38,6 @@ import org.junit.Test;
import org.onlab.graph.GraphPathSearch;
import org.onlab.junit.TestUtils;
import org.onlab.junit.TestUtils.TestUtilsException;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IPv4;
import org.onlab.packet.TCP;
import org.onlab.util.Bandwidth;
import org.onosproject.common.DefaultTopologyGraph;
import org.onosproject.core.ApplicationId;
......@@ -54,9 +45,6 @@ import org.onosproject.core.CoreServiceAdapter;
import org.onosproject.core.DefaultApplicationId;
import org.onosproject.core.IdGenerator;
import org.onosproject.event.Event;
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.incubator.net.tunnel.DefaultTunnel;
import org.onosproject.incubator.net.tunnel.Tunnel;
import org.onosproject.incubator.net.tunnel.Tunnel.State;
......@@ -67,34 +55,20 @@ import org.onosproject.incubator.net.tunnel.TunnelListener;
import org.onosproject.mastership.MastershipServiceAdapter;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.Annotations;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultAnnotations.Builder;
import org.onosproject.net.DefaultDevice;
import org.onosproject.net.DefaultLink;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.ElementId;
import org.onosproject.net.Link;
import org.onosproject.net.MastershipRole;
import org.onosproject.net.Path;
import org.onosproject.net.PortNumber;
import org.onosproject.net.SparseAnnotations;
import org.onosproject.net.device.DeviceEvent;
import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.flowobjective.ForwardingObjective;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.link.LinkEvent;
import org.onosproject.net.link.LinkListener;
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.PacketProcessor;
import org.onosproject.net.packet.PacketService;
import org.onosproject.net.packet.PacketServiceAdapter;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.net.resource.Resource;
import org.onosproject.net.topology.DefaultTopologyEdge;
......@@ -112,10 +86,7 @@ import org.onosproject.pce.pceservice.PathComputationTest.MockNetConfigRegistryA
import org.onosproject.pce.pceservice.PathComputationTest.MockPathResourceService;
import org.onosproject.pce.pceservice.constraint.CostConstraint;
import org.onosproject.pce.pcestore.api.PceStore;
import org.onosproject.pce.util.FlowObjServiceAdapter;
import org.onosproject.pce.util.LabelResourceAdapter;
import org.onosproject.pce.util.MockDeviceService;
import org.onosproject.pce.util.MockLinkService;
import org.onosproject.pce.util.PceStoreAdapter;
import org.onosproject.pce.util.TunnelServiceAdapter;
import org.onosproject.pcep.api.DeviceCapability;
......@@ -137,14 +108,9 @@ public class PceManagerTest {
private MockCoreService coreService = new MockCoreService();
private MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter();
private TestStorageService storageService = new TestStorageService();
private PacketService packetService = new MockPacketService();
private MockDeviceService deviceService = new MockDeviceService();
private MockNetConfigRegistryAdapter netConfigRegistry = new PathComputationTest.MockNetConfigRegistryAdapter();
private MockLinkService linkService = new MockLinkService();
private MockFlowObjService flowObjectiveService = new MockFlowObjService();
private PceStore pceStore = new PceStoreAdapter();
private LabelResourceService labelResourceService = new LabelResourceAdapter();
private LabelResourceAdminService labelRsrcAdminService = new LabelResourceAdapter();
public static ProviderId providerId = new ProviderId("pce", "foo");
private static final String L3 = "L3";
......@@ -173,13 +139,8 @@ public class PceManagerTest {
pceManager.tunnelService = tunnelService;
pceManager.coreService = coreService;
pceManager.storageService = storageService;
pceManager.packetService = packetService;
pceManager.deviceService = deviceService;
pceManager.linkService = linkService;
pceManager.netCfgService = netConfigRegistry;
pceManager.labelRsrcAdminService = labelRsrcAdminService;
pceManager.labelRsrcService = labelResourceService;
pceManager.flowObjectiveService = flowObjectiveService;
pceManager.pceStore = pceStore;
pceManager.mastershipService = mastershipService;
pceManager.activate();
......@@ -452,29 +413,6 @@ public class PceManagerTest {
}
/**
* Tests path setup without failure for LSP with signalling and with bandwidth reservation.
*/
@Test
public void setupPathTest11() {
build4RouterTopo(false, true, true, true, 15);
List<Constraint> constraints = new LinkedList<Constraint>();
BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0));
CostConstraint costConstraint = new CostConstraint(TE_COST);
constraints.add(costConstraint);
constraints.add(bwConstraint);
LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, SR_WITHOUT_SIGNALLING);
assertThat(result, is(false));
}
/**
* Tests path setup without signalling and with bandwidth reservation.
*/
@Test
......@@ -487,24 +425,6 @@ public class PceManagerTest {
constraints.add(costConstraint);
constraints.add(bwConstraint);
LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
LabelResourceId link1Label = LabelResourceId.labelResourceId(5202);
pceManager.pceStore.addAdjLabel(link1, link1Label);
LabelResourceId link2Label = LabelResourceId.labelResourceId(5203);
pceManager.pceStore.addAdjLabel(link2, link2Label);
LabelResourceId link3Label = LabelResourceId.labelResourceId(5204);
pceManager.pceStore.addAdjLabel(link3, link3Label);
LabelResourceId link4Label = LabelResourceId.labelResourceId(5205);
pceManager.pceStore.addAdjLabel(link4, link4Label);
boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, SR_WITHOUT_SIGNALLING);
assertThat(result, is(true));
}
......@@ -572,24 +492,6 @@ public class PceManagerTest {
CostConstraint costConstraint = new CostConstraint(TE_COST);
constraints.add(costConstraint);
LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
LabelResourceId link1Label = LabelResourceId.labelResourceId(5202);
pceManager.pceStore.addAdjLabel(link1, link1Label);
LabelResourceId link2Label = LabelResourceId.labelResourceId(5203);
pceManager.pceStore.addAdjLabel(link2, link2Label);
LabelResourceId link3Label = LabelResourceId.labelResourceId(5204);
pceManager.pceStore.addAdjLabel(link3, link3Label);
LabelResourceId link4Label = LabelResourceId.labelResourceId(5205);
pceManager.pceStore.addAdjLabel(link4, link4Label);
boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, SR_WITHOUT_SIGNALLING);
assertThat(result, is(true));
......@@ -685,89 +587,6 @@ public class PceManagerTest {
}
/**
* Tests packet in to trigger label DB sync.
*/
@Test
public void packetProcessingTest1() throws URISyntaxException {
build4RouterTopo(false, true, true, true, 0); // This also initializes devices etc.
LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
pceManager.pceStore.addLsrIdDevice(deviceD1.annotations().value(LSRID), deviceD1.id());
pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
ConnectPoint src = new ConnectPoint(D1.deviceId(), PortNumber.portNumber(1));
ConnectPoint dst = new ConnectPoint(D2.deviceId(), PortNumber.portNumber(2));
Link link1 = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).type(DIRECT)
.providerId(new ProviderId("eth", "1")).build();
LabelResourceId link1Label = LabelResourceId.labelResourceId(5204);
pceManager.pceStore.addAdjLabel(link1, link1Label);
TCP tcp = new TCP();
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);
InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(DeviceId.deviceId("1.1.1.1"),
PortNumber.portNumber(PCEP_PORT)),
eth, null);
pktProcessor.process(new MockPcepPacketContext(inPkt, null));
assertThat(flowsDownloaded, is(4));
}
/**
* Tests faulty packet in to trigger label DB sync.
*/
@Test
public void packetProcessingTest2() throws URISyntaxException {
build4RouterTopo(false, true, true, true, 0); // This also initializes devices etc.
LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
ConnectPoint src = new ConnectPoint(D1.deviceId(), PortNumber.portNumber(1));
ConnectPoint dst = new ConnectPoint(D2.deviceId(), PortNumber.portNumber(2));
Link link1 = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).type(DIRECT)
.providerId(new ProviderId("eth", "1")).build();
LabelResourceId link1Label = LabelResourceId.labelResourceId(5204);
pceManager.pceStore.addAdjLabel(link1, link1Label);
TCP tcp = new TCP(); // Not set the 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);
InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(D1.deviceId(),
PortNumber.portNumber(PCEP_PORT)),
eth, null);
pktProcessor.process(new MockPcepPacketContext(inPkt, null));
assertThat(flowsDownloaded, is(0));
}
/**
* Tests tunnel events added and removed.
*/
@Test
......@@ -780,24 +599,6 @@ public class PceManagerTest {
constraints.add(costConstraint);
constraints.add(bwConstraint);
LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
LabelResourceId link1Label = LabelResourceId.labelResourceId(5202);
pceManager.pceStore.addAdjLabel(link1, link1Label);
LabelResourceId link2Label = LabelResourceId.labelResourceId(5203);
pceManager.pceStore.addAdjLabel(link2, link2Label);
LabelResourceId link3Label = LabelResourceId.labelResourceId(5204);
pceManager.pceStore.addAdjLabel(link3, link3Label);
LabelResourceId link4Label = LabelResourceId.labelResourceId(5205);
pceManager.pceStore.addAdjLabel(link4, link4Label);
pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T1", constraints, SR_WITHOUT_SIGNALLING);
assertThat(pceStore.getTunnelInfoCount(), is(1));
......@@ -1276,86 +1077,6 @@ public class PceManagerTest {
assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
}
/*
* Tests node label allocation/removal in SR-TE case based on device event.
*/
@Test
public void deviceEventTest() {
// Make four router topology with SR-TE capabilities.
build4RouterTopo(true, false, true, true, 0);
// Add new L3 device
DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder();
builderDev5.set(AnnotationKeys.TYPE, L3);
builderDev5.set(LSRID, "5.5.5.5");
Device dev5 = new MockDevice(DeviceId.deviceId("P005"), builderDev5.build());
deviceService.addDevice(dev5);
// Add capability
DeviceCapability device5Cap = netConfigRegistry.addConfig(DeviceId.deviceId("5.5.5.5"), DeviceCapability.class);
device5Cap.setLabelStackCap(true)
.setLocalLabelCap(false)
.setSrCap(true)
.apply();
// Get listener
DeviceListener listener = deviceService.getListener();
// Generate Remove events
deviceService.removeDevice(dev5);
DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_REMOVED, dev5);
listener.event(event);
assertThat(pceStore.getGlobalNodeLabel(dev5.id()), is(nullValue()));
}
/**
* Tests adjacency label allocation/removal in SR-TE case based on link event.
*/
@Test
public void linkEventTest() {
// Make four router topology with SR-TE capabilities.
build4RouterTopo(true, false, true, true, 0);
// Get listener
LinkListener listener = linkService.getListener();
// Adding link3
linkService.addLink(link3);
// Generate events
LinkEvent event = new LinkEvent(LinkEvent.Type.LINK_ADDED, link3);
listener.event(event);
assertThat(pceStore.getAdjLabel(link3), is(notNullValue()));
// Adding link4
linkService.addLink(link4);
event = new LinkEvent(LinkEvent.Type.LINK_ADDED, link4);
listener.event(event);
assertThat(pceStore.getAdjLabel(link4), is(notNullValue()));
// Remove link3
linkService.removeLink(link3);
// Generate events
event = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3);
listener.event(event);
assertThat(pceStore.getAdjLabel(link3), is(nullValue()));
// Remove link4
linkService.removeLink(link4);
event = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
listener.event(event);
assertThat(pceStore.getAdjLabel(link4), is(nullValue()));
}
@After
public void tearDown() {
pceManager.deactivate();
......@@ -1364,13 +1085,8 @@ public class PceManagerTest {
pceManager.tunnelService = null;
pceManager.coreService = null;
pceManager.storageService = null;
pceManager.packetService = null;
pceManager.deviceService = null;
pceManager.linkService = null;
pceManager.netCfgService = null;
pceManager.labelRsrcAdminService = null;
pceManager.labelRsrcService = null;
pceManager.flowObjectiveService = null;
pceManager.pceStore = null;
pceManager.topologyService = null;
pceManager.mastershipService = null;
......@@ -1588,31 +1304,4 @@ public class PceManagerTest {
super(null, id, null, null, null, null, null, null, annotations);
}
}
private PacketProcessor pktProcessor = null;
private class MockPacketService extends PacketServiceAdapter {
@Override
public void addProcessor(PacketProcessor processor, int priority) {
pktProcessor = processor;
}
}
// Minimal PacketContext to make core and applications happy.
final class MockPcepPacketContext extends DefaultPacketContext {
private MockPcepPacketContext(InboundPacket inPkt, OutboundPacket outPkt) {
super(System.currentTimeMillis(), inPkt, outPkt, false);
}
@Override
public void send() {
}
}
public static class MockFlowObjService extends FlowObjServiceAdapter {
@Override
public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) {
++flowsDownloaded;
}
}
}
......
......@@ -30,15 +30,12 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.onlab.util.DataRateUnit;
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.tunnel.TunnelId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultLink;
import org.onosproject.net.DeviceId;
import org.onosproject.net.ElementId;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.Link;
......@@ -46,7 +43,6 @@ import org.onosproject.net.PortNumber;
import org.onosproject.net.resource.ResourceConsumer;
import org.onosproject.pce.pceservice.LspType;
import org.onosproject.pce.pceservice.TunnelConsumerId;
import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.store.service.TestStorageService;
......@@ -68,24 +64,18 @@ public class DistributedPceStoreTest {
private PortNumber portNumber2 = PortNumber.portNumber(2);
private PortNumber portNumber3 = PortNumber.portNumber(3);
private PortNumber portNumber4 = PortNumber.portNumber(4);
private ConnectPoint srcConnectionPoint1 = new ConnectPoint((ElementId) deviceId1, portNumber1);
private ConnectPoint dstConnectionPoint2 = new ConnectPoint((ElementId) deviceId2, portNumber2);
private ConnectPoint srcConnectionPoint3 = new ConnectPoint((ElementId) deviceId3, portNumber3);
private ConnectPoint dstConnectionPoint4 = new ConnectPoint((ElementId) deviceId4, portNumber4);
private LabelResource labelResource1 = new DefaultLabelResource(deviceId1, labelId1);
private LabelResource labelResource2 = new DefaultLabelResource(deviceId2, labelId2);
private LabelResource labelResource3 = new DefaultLabelResource(deviceId3, labelId3);
private LabelResource labelResource4 = new DefaultLabelResource(deviceId4, labelId4);
private ConnectPoint srcConnectionPoint1 = new ConnectPoint(deviceId1, portNumber1);
private ConnectPoint dstConnectionPoint2 = new ConnectPoint(deviceId2, portNumber2);
private ConnectPoint srcConnectionPoint3 = new ConnectPoint(deviceId3, portNumber3);
private ConnectPoint dstConnectionPoint4 = new ConnectPoint(deviceId4, portNumber4);
private Link link1;
private Link link2;
private List<LabelResource> labelList1 = new LinkedList<>();
private List<LabelResource> labelList2 = new LinkedList<>();
private TunnelId tunnelId1 = TunnelId.valueOf("1");
private TunnelId tunnelId2 = TunnelId.valueOf("2");
private TunnelId tunnelId3 = TunnelId.valueOf("3");
private TunnelId tunnelId4 = TunnelId.valueOf("4");
private PceccTunnelInfo pceccTunnelInfo1;
private PceccTunnelInfo pceccTunnelInfo2;
private ResourceConsumer tunnelConsumerId1 = TunnelConsumerId.valueOf(10);
private ResourceConsumer tunnelConsumerId2 = TunnelConsumerId.valueOf(20);
private PcePathInfo failedPathInfo1;
private PcePathInfo failedPathInfo2;
private PcePathInfo failedPathInfo3;
......@@ -120,44 +110,6 @@ public class DistributedPceStoreTest {
.type(Link.Type.DIRECT)
.state(Link.State.ACTIVE)
.build();
labelList1.add(labelResource1);
labelList1.add(labelResource2);
labelList2.add(labelResource3);
labelList2.add(labelResource4);
// Create pceccTunnelInfo1
List<LspLocalLabelInfo> lspLocalLabelInfoList1 = new LinkedList<>();
ResourceConsumer tunnelConsumerId1 = TunnelConsumerId.valueOf(10);
DeviceId deviceId1 = DeviceId.deviceId("foo");
LabelResourceId inLabelId1 = LabelResourceId.labelResourceId(1);
LabelResourceId outLabelId1 = LabelResourceId.labelResourceId(2);
LspLocalLabelInfo lspLocalLabel1 = DefaultLspLocalLabelInfo.builder()
.deviceId(deviceId1)
.inLabelId(inLabelId1)
.outLabelId(outLabelId1)
.build();
lspLocalLabelInfoList1.add(lspLocalLabel1);
pceccTunnelInfo1 = new PceccTunnelInfo(lspLocalLabelInfoList1, tunnelConsumerId1);
// Create pceccTunnelInfo2
List<LspLocalLabelInfo> lspLocalLabelInfoList2 = new LinkedList<>();
ResourceConsumer tunnelConsumerId2 = TunnelConsumerId.valueOf(20);
DeviceId deviceId2 = DeviceId.deviceId("foo");
LabelResourceId inLabelId2 = LabelResourceId.labelResourceId(3);
LabelResourceId outLabelId2 = LabelResourceId.labelResourceId(4);
LspLocalLabelInfo lspLocalLabel2 = DefaultLspLocalLabelInfo.builder()
.deviceId(deviceId2)
.inLabelId(inLabelId2)
.outLabelId(outLabelId2)
.build();
lspLocalLabelInfoList2.add(lspLocalLabel2);
pceccTunnelInfo2 = new PceccTunnelInfo(lspLocalLabelInfoList2, tunnelConsumerId2);
// Creates failedPathInfo1
DeviceId src1 = DeviceId.deviceId("foo1");
......@@ -209,42 +161,6 @@ public class DistributedPceStoreTest {
}
/**
* Checks the operation of addGlobalNodeLabel() method.
*/
@Test
public void testAddGlobalNodeLabel() {
// initialization
distrPceStore.storageService = new TestStorageService();
distrPceStore.activate();
// add device with label
distrPceStore.addGlobalNodeLabel(deviceId1, labelId1);
assertThat(distrPceStore.existsGlobalNodeLabel(deviceId1), is(true));
assertThat(distrPceStore.getGlobalNodeLabel(deviceId1), is(labelId1));
distrPceStore.addGlobalNodeLabel(deviceId2, labelId2);
assertThat(distrPceStore.existsGlobalNodeLabel(deviceId2), is(true));
assertThat(distrPceStore.getGlobalNodeLabel(deviceId2), is(labelId2));
}
/**
* Checks the operation of addAdjLabel() method.
*/
@Test
public void testAddAdjLabel() {
// initialization
distrPceStore.storageService = new TestStorageService();
distrPceStore.activate();
// link with list of labels
distrPceStore.addAdjLabel(link1, labelId1);
assertThat(distrPceStore.existsAdjLabel(link1), is(true));
assertThat(distrPceStore.getAdjLabel(link1), is(labelId1));
distrPceStore.addAdjLabel(link2, labelId2);
assertThat(distrPceStore.existsAdjLabel(link2), is(true));
assertThat(distrPceStore.getAdjLabel(link2), is(labelId2));
}
/**
* Checks the operation of addTunnelInfo() method.
*/
@Test
......@@ -254,12 +170,12 @@ public class DistributedPceStoreTest {
distrPceStore.activate();
// TunnelId with device label store information
distrPceStore.addTunnelInfo(tunnelId1, pceccTunnelInfo1);
distrPceStore.addTunnelInfo(tunnelId1, tunnelConsumerId1);
assertThat(distrPceStore.existsTunnelInfo(tunnelId1), is(true));
assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(pceccTunnelInfo1));
distrPceStore.addTunnelInfo(tunnelId2, pceccTunnelInfo2);
assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(tunnelConsumerId1));
distrPceStore.addTunnelInfo(tunnelId2, tunnelConsumerId2);
assertThat(distrPceStore.existsTunnelInfo(tunnelId2), is(true));
assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(pceccTunnelInfo2));
assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(tunnelConsumerId2));
}
/**
......@@ -279,30 +195,6 @@ public class DistributedPceStoreTest {
}
/**
* Checks the operation of existsGlobalNodeLabel() method.
*/
@Test
public void testExistsGlobalNodeLabel() {
testAddGlobalNodeLabel();
assertThat(distrPceStore.existsGlobalNodeLabel(deviceId1), is(true));
assertThat(distrPceStore.existsGlobalNodeLabel(deviceId2), is(true));
assertThat(distrPceStore.existsGlobalNodeLabel(deviceId3), is(false));
assertThat(distrPceStore.existsGlobalNodeLabel(deviceId4), is(false));
}
/**
* Checks the operation of existsAdjLabel() method.
*/
@Test
public void testExistsAdjLabel() {
testAddAdjLabel();
assertThat(distrPceStore.existsAdjLabel(link1), is(true));
assertThat(distrPceStore.existsAdjLabel(link2), is(true));
}
/**
* Checks the operation of existsTunnelInfo() method.
*/
@Test
......@@ -329,26 +221,6 @@ public class DistributedPceStoreTest {
}
/**
* Checks the operation of getGlobalNodeLabelCount() method.
*/
@Test
public void testGetGlobalNodeLabelCount() {
testAddGlobalNodeLabel();
assertThat(distrPceStore.getGlobalNodeLabelCount(), is(2));
}
/**
* Checks the operation of getAdjLabelCount() method.
*/
@Test
public void testGetAdjLabelCount() {
testAddAdjLabel();
assertThat(distrPceStore.getAdjLabelCount(), is(2));
}
/**
* Checks the operation of getTunnelInfoCount() method.
*/
@Test
......@@ -369,39 +241,13 @@ public class DistributedPceStoreTest {
}
/**
* Checks the operation of getGlobalNodeLabels() method.
*/
@Test
public void testGetGlobalNodeLabels() {
testAddGlobalNodeLabel();
Map<DeviceId, LabelResourceId> nodeLabelMap = distrPceStore.getGlobalNodeLabels();
assertThat(nodeLabelMap, is(notNullValue()));
assertThat(nodeLabelMap.isEmpty(), is(false));
assertThat(nodeLabelMap.size(), is(2));
}
/**
* Checks the operation of getAdjLabels() method.
*/
@Test
public void testGetAdjLabels() {
testAddAdjLabel();
Map<Link, LabelResourceId> adjLabelMap = distrPceStore.getAdjLabels();
assertThat(adjLabelMap, is(notNullValue()));
assertThat(adjLabelMap.isEmpty(), is(false));
assertThat(adjLabelMap.size(), is(2));
}
/**
* Checks the operation of getTunnelInfos() method.
*/
@Test
public void testGetTunnelInfos() {
testAddTunnelInfo();
Map<TunnelId, PceccTunnelInfo> tunnelInfoMap = distrPceStore.getTunnelInfos();
Map<TunnelId, ResourceConsumer> tunnelInfoMap = distrPceStore.getTunnelInfos();
assertThat(tunnelInfoMap, is(notNullValue()));
assertThat(tunnelInfoMap.isEmpty(), is(false));
assertThat(tunnelInfoMap.size(), is(2));
......@@ -420,38 +266,6 @@ public class DistributedPceStoreTest {
}
/**
* Checks the operation of getGlobalNodeLabel() method.
*/
@Test
public void testGetGlobalNodeLabel() {
testAddGlobalNodeLabel();
// deviceId1 with labelId1
assertThat(deviceId1, is(notNullValue()));
assertThat(distrPceStore.getGlobalNodeLabel(deviceId1), is(labelId1));
// deviceId2 with labelId2
assertThat(deviceId2, is(notNullValue()));
assertThat(distrPceStore.getGlobalNodeLabel(deviceId2), is(labelId2));
}
/**
* Checks the operation of getAdjLabel() method.
*/
@Test
public void testGetAdjLabel() {
testAddAdjLabel();
// link1 with labels
assertThat(link1, is(notNullValue()));
assertThat(distrPceStore.getAdjLabel(link1), is(labelId1));
// link2 with labels
assertThat(link2, is(notNullValue()));
assertThat(distrPceStore.getAdjLabel(link2), is(labelId2));
}
/**
* Checks the operation of getTunnelInfo() method.
*/
@Test
......@@ -460,88 +274,11 @@ public class DistributedPceStoreTest {
// tunnelId1 with device label store info
assertThat(tunnelId1, is(notNullValue()));
assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(pceccTunnelInfo1));
assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(tunnelConsumerId1));
// tunnelId2 with device label store info
assertThat(tunnelId2, is(notNullValue()));
assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(pceccTunnelInfo2));
}
/**
* Checks the operation of updateTunnelInfo() method.
*/
@Test
public void testUpdateTunnelInfo() {
// add tunnel info
testAddTunnelInfo();
// new updates
// Create pceccTunnelInfo3
List<LspLocalLabelInfo> lspLocalLabelInfoList3 = new LinkedList<>();
ResourceConsumer tunnelConsumerId3 = TunnelConsumerId.valueOf(30);
DeviceId deviceId3 = DeviceId.deviceId("goo");
LabelResourceId inLabelId3 = LabelResourceId.labelResourceId(3);
LabelResourceId outLabelId3 = LabelResourceId.labelResourceId(4);
LspLocalLabelInfo lspLocalLabel3 = DefaultLspLocalLabelInfo.builder()
.deviceId(deviceId3)
.inLabelId(inLabelId3)
.outLabelId(outLabelId3)
.build();
lspLocalLabelInfoList3.add(lspLocalLabel3);
PceccTunnelInfo pceccTunnelInfo3 = new PceccTunnelInfo(lspLocalLabelInfoList3, tunnelConsumerId3);
// Create pceccTunnelInfo4
List<LspLocalLabelInfo> lspLocalLabelInfoList4 = new LinkedList<>();
ResourceConsumer tunnelConsumerId4 = TunnelConsumerId.valueOf(40);
DeviceId deviceId4 = DeviceId.deviceId("goo");
LabelResourceId inLabelId4 = LabelResourceId.labelResourceId(4);
LabelResourceId outLabelId4 = LabelResourceId.labelResourceId(5);
LspLocalLabelInfo lspLocalLabel4 = DefaultLspLocalLabelInfo.builder()
.deviceId(deviceId4)
.inLabelId(inLabelId4)
.outLabelId(outLabelId4)
.build();
lspLocalLabelInfoList4.add(lspLocalLabel4);
PceccTunnelInfo pceccTunnelInfo4 = new PceccTunnelInfo(lspLocalLabelInfoList4, tunnelConsumerId4);
// update only lspLocalLabelInfoList
assertThat(distrPceStore.updateTunnelInfo(tunnelId1, lspLocalLabelInfoList3), is(true));
assertThat(distrPceStore.updateTunnelInfo(tunnelId2, lspLocalLabelInfoList4), is(true));
// update only tunnelConsumerId
assertThat(distrPceStore.updateTunnelInfo(tunnelId1, tunnelConsumerId3), is(true));
assertThat(distrPceStore.updateTunnelInfo(tunnelId2, tunnelConsumerId4), is(true));
assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(pceccTunnelInfo3));
assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(pceccTunnelInfo4));
}
/**
* Checks the operation of removeGlobalNodeLabel() method.
*/
@Test
public void testRemoveGlobalNodeLabel() {
testAddGlobalNodeLabel();
assertThat(distrPceStore.removeGlobalNodeLabel(deviceId1), is(true));
assertThat(distrPceStore.removeGlobalNodeLabel(deviceId2), is(true));
}
/**
* Checks the operation of removeAdjLabel() method.
*/
@Test
public void testRemoveAdjLabel() {
testAddAdjLabel();
assertThat(distrPceStore.removeAdjLabel(link1), is(true));
assertThat(distrPceStore.removeAdjLabel(link2), is(true));
assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(tunnelConsumerId2));
}
/**
......
/*
* 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.pcestore;
import java.util.LinkedList;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.incubator.net.resource.label.LabelResourceId;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.resource.ResourceConsumer;
import org.onosproject.pce.pceservice.TunnelConsumerId;
import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
/**
* Unit tests for PceccTunnelInfo class.
*/
public class PceccTunnelInfoTest {
/**
* Checks the operation of equals() methods.
*/
@Test
public void testEquals() {
// create same two objects.
List<LspLocalLabelInfo> lspLocalLabelList1 = new LinkedList<>();
ResourceConsumer tunnelConsumerId1 = TunnelConsumerId.valueOf(10);
// create object of DefaultLspLocalLabelInfo
DeviceId deviceId1 = DeviceId.deviceId("foo");
LabelResourceId inLabelId1 = LabelResourceId.labelResourceId(1);
LabelResourceId outLabelId1 = LabelResourceId.labelResourceId(2);
PortNumber inPort1 = PortNumber.portNumber(5122);
PortNumber outPort1 = PortNumber.portNumber(5123);
LspLocalLabelInfo lspLocalLabel1 = DefaultLspLocalLabelInfo.builder()
.deviceId(deviceId1)
.inLabelId(inLabelId1)
.outLabelId(outLabelId1)
.inPort(inPort1)
.outPort(outPort1)
.build();
lspLocalLabelList1.add(lspLocalLabel1);
PceccTunnelInfo pceccTunnelInfo1 = new PceccTunnelInfo(lspLocalLabelList1, tunnelConsumerId1);
// create same as above object
PceccTunnelInfo samePceccTunnelInfo1 = new PceccTunnelInfo(lspLocalLabelList1, tunnelConsumerId1);
// Create different object.
List<LspLocalLabelInfo> lspLocalLabelInfoList2 = new LinkedList<>();
ResourceConsumer tunnelConsumerId2 = TunnelConsumerId.valueOf(20);
// create object of DefaultLspLocalLabelInfo
DeviceId deviceId2 = DeviceId.deviceId("goo");
LabelResourceId inLabelId2 = LabelResourceId.labelResourceId(3);
LabelResourceId outLabelId2 = LabelResourceId.labelResourceId(4);
PortNumber inPort2 = PortNumber.portNumber(5124);
PortNumber outPort2 = PortNumber.portNumber(5125);
LspLocalLabelInfo lspLocalLabel2 = DefaultLspLocalLabelInfo.builder()
.deviceId(deviceId2)
.inLabelId(inLabelId2)
.outLabelId(outLabelId2)
.inPort(inPort2)
.outPort(outPort2)
.build();
lspLocalLabelInfoList2.add(lspLocalLabel2);
PceccTunnelInfo pceccTunnelInfo2 = new PceccTunnelInfo(lspLocalLabelInfoList2, tunnelConsumerId2);
new EqualsTester().addEqualityGroup(pceccTunnelInfo1, samePceccTunnelInfo1)
.addEqualityGroup(pceccTunnelInfo2)
.testEquals();
}
/**
* Checks the construction of a PceccTunnelInfo object.
*/
@Test
public void testConstruction() {
List<LspLocalLabelInfo> lspLocalLabelInfoList = new LinkedList<>();
ResourceConsumer tunnelConsumerId = TunnelConsumerId.valueOf(10);
// create object of DefaultLspLocalLabelInfo
DeviceId deviceId = DeviceId.deviceId("foo");
LabelResourceId inLabelId = LabelResourceId.labelResourceId(1);
LabelResourceId outLabelId = LabelResourceId.labelResourceId(2);
PortNumber inPort = PortNumber.portNumber(5122);
PortNumber outPort = PortNumber.portNumber(5123);
LspLocalLabelInfo lspLocalLabelInfo = DefaultLspLocalLabelInfo.builder()
.deviceId(deviceId)
.inLabelId(inLabelId)
.outLabelId(outLabelId)
.inPort(inPort)
.outPort(outPort)
.build();
lspLocalLabelInfoList.add(lspLocalLabelInfo);
PceccTunnelInfo pceccTunnelInfo = new PceccTunnelInfo(lspLocalLabelInfoList, tunnelConsumerId);
assertThat(lspLocalLabelInfoList, is(pceccTunnelInfo.lspLocalLabelInfoList()));
}
}
......@@ -22,19 +22,14 @@ import java.util.concurrent.ConcurrentMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.onosproject.incubator.net.resource.label.LabelResourceId;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.resource.ResourceConsumer;
import org.onosproject.pce.pcestore.PceccTunnelInfo;
import org.onosproject.pce.pcestore.PcePathInfo;
import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
import org.onosproject.pce.pcestore.api.PceStore;
/**
......@@ -42,14 +37,8 @@ import org.onosproject.pce.pcestore.api.PceStore;
*/
public class PceStoreAdapter implements PceStore {
// Mapping device with global node label
private ConcurrentMap<DeviceId, LabelResourceId> globalNodeLabelMap = new ConcurrentHashMap<>();
// Mapping link with adjacency label
private ConcurrentMap<Link, LabelResourceId> adjLabelMap = new ConcurrentHashMap<>();
// Mapping tunnel with device local info with tunnel consumer id
private ConcurrentMap<TunnelId, PceccTunnelInfo> tunnelInfoMap = new ConcurrentHashMap<>();
private ConcurrentMap<TunnelId, ResourceConsumer> tunnelInfoMap = new ConcurrentHashMap<>();
// Set of Path info
private Set<PcePathInfo> failedPathInfoSet = new HashSet<>();
......@@ -58,16 +47,6 @@ public class PceStoreAdapter implements PceStore {
private Map<String, DeviceId> lsrIdDeviceIdMap = new HashMap<>();
@Override
public boolean existsGlobalNodeLabel(DeviceId id) {
return globalNodeLabelMap.containsKey(id);
}
@Override
public boolean existsAdjLabel(Link link) {
return adjLabelMap.containsKey(link);
}
@Override
public boolean existsTunnelInfo(TunnelId tunnelId) {
return tunnelInfoMap.containsKey(tunnelId);
}
......@@ -78,16 +57,6 @@ public class PceStoreAdapter implements PceStore {
}
@Override
public int getGlobalNodeLabelCount() {
return globalNodeLabelMap.size();
}
@Override
public int getAdjLabelCount() {
return adjLabelMap.size();
}
@Override
public int getTunnelInfoCount() {
return tunnelInfoMap.size();
}
......@@ -98,21 +67,9 @@ public class PceStoreAdapter implements PceStore {
}
@Override
public Map<DeviceId, LabelResourceId> getGlobalNodeLabels() {
return globalNodeLabelMap.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue()));
}
@Override
public Map<Link, LabelResourceId> getAdjLabels() {
return adjLabelMap.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue()));
}
@Override
public Map<TunnelId, PceccTunnelInfo> getTunnelInfos() {
public Map<TunnelId, ResourceConsumer> getTunnelInfos() {
return tunnelInfoMap.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> (PceccTunnelInfo) e.getValue()));
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue()));
}
@Override
......@@ -121,33 +78,13 @@ public class PceStoreAdapter implements PceStore {
}
@Override
public LabelResourceId getGlobalNodeLabel(DeviceId id) {
return globalNodeLabelMap.get(id);
}
@Override
public LabelResourceId getAdjLabel(Link link) {
return adjLabelMap.get(link);
}
@Override
public PceccTunnelInfo getTunnelInfo(TunnelId tunnelId) {
public ResourceConsumer getTunnelInfo(TunnelId tunnelId) {
return tunnelInfoMap.get(tunnelId);
}
@Override
public void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId) {
globalNodeLabelMap.put(deviceId, labelId);
}
@Override
public void addAdjLabel(Link link, LabelResourceId labelId) {
adjLabelMap.put(link, labelId);
}
@Override
public void addTunnelInfo(TunnelId tunnelId, PceccTunnelInfo pceccTunnelInfo) {
tunnelInfoMap.put(tunnelId, pceccTunnelInfo);
public void addTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId) {
tunnelInfoMap.put(tunnelId, tunnelConsumerId);
}
@Override
......@@ -156,48 +93,6 @@ public class PceStoreAdapter implements PceStore {
}
@Override
public boolean updateTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList) {
if (!tunnelInfoMap.containsKey((tunnelId))) {
return false;
}
PceccTunnelInfo labelStoreInfo = tunnelInfoMap.get(tunnelId);
labelStoreInfo.lspLocalLabelInfoList(lspLocalLabelInfoList);
tunnelInfoMap.put(tunnelId, labelStoreInfo);
return true;
}
@Override
public boolean updateTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId) {
if (!tunnelInfoMap.containsKey((tunnelId))) {
return false;
}
PceccTunnelInfo tunnelInfo = tunnelInfoMap.get(tunnelId);
tunnelInfo.tunnelConsumerId(tunnelConsumerId);
tunnelInfoMap.put(tunnelId, tunnelInfo);
return true;
}
@Override
public boolean removeGlobalNodeLabel(DeviceId id) {
globalNodeLabelMap.remove(id);
if (globalNodeLabelMap.containsKey(id)) {
return false;
}
return true;
}
@Override
public boolean removeAdjLabel(Link link) {
adjLabelMap.remove(link);
if (adjLabelMap.containsKey(link)) {
return false;
}
return true;
}
@Override
public boolean removeTunnelInfo(TunnelId tunnelId) {
tunnelInfoMap.remove(tunnelId);
if (tunnelInfoMap.containsKey(tunnelId)) {
......@@ -213,39 +108,4 @@ public class PceStoreAdapter implements PceStore {
}
return true;
}
@Override
public boolean addLsrIdDevice(String lsrId, DeviceId deviceId) {
lsrIdDeviceIdMap.put(lsrId, deviceId);
return true;
}
@Override
public boolean removeLsrIdDevice(String lsrId) {
lsrIdDeviceIdMap.remove(lsrId);
return true;
}
@Override
public DeviceId getLsrIdDevice(String lsrId) {
return lsrIdDeviceIdMap.get(lsrId);
}
@Override
public boolean addPccLsr(DeviceId lsrId) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean removePccLsr(DeviceId lsrId) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean hasPccLsr(DeviceId lsrId) {
// TODO Auto-generated method stub
return false;
}
}
......
......@@ -16,8 +16,14 @@
package org.onosproject.pcep.controller;
import java.util.Collection;
import java.util.LinkedList;
import org.onosproject.incubator.net.tunnel.DefaultLabelStack;
import org.onosproject.incubator.net.tunnel.LabelStack;
import org.onosproject.incubator.net.tunnel.Tunnel;
import org.onosproject.net.Path;
import org.onosproject.pcepio.protocol.PcepMessage;
import org.onosproject.pcepio.types.PcepValueType;
/**
* Abstraction of an Pcep client controller. Serves as a one stop
......@@ -85,20 +91,6 @@ public interface PcepClientController {
void removeNodeListener(PcepNodeListener listener);
/**
* Register a listener for packet events.
*
* @param listener the listener to notify
*/
void addPacketListener(PcepPacketListener listener);
/**
* Unregister a packet listener.
*
* @param listener the listener to unregister
*/
void removePacketListener(PcepPacketListener listener);
/**
* Send a message to a particular pcc client.
*
* @param pccId the id of the client to send message.
......@@ -118,4 +110,29 @@ public interface PcepClientController {
* Close all connected PCC clients.
*/
void closeConnectedClients();
/**
* Create label stack from the given path.
*
* @param path from which label stack is to be computed
* @return the label stack
*/
public LabelStack computeLabelStack(Path path);
/**
* Allocates and downloads local labels for the given LSP.
*
* @param tunnel for which local labels have to be assigned and downloaded
* @return success or failure
*/
public boolean allocateLocalLabel(Tunnel tunnel);
/**
* Creates label stack for ERO object from network resource.
*
* @param labelStack
* @param path (hop list)
* @return list of ERO sub-objects
*/
public LinkedList<PcepValueType> createPcepLabelStack(DefaultLabelStack labelStack, Path path);
}
......
COMPILE_DEPS = [
'//lib:CORE_DEPS',
'//incubator/api:onos-incubator-api',
'//protocols/pcep/pcepio:onos-protocols-pcep-pcepio',
'//protocols/pcep/api:onos-protocols-pcep-api',
'//incubator/api:onos-incubator-api',
'//core/store/serializers:onos-core-serializers',
'//apps/pcep-api:onos-apps-pcep-api',
]
......
......@@ -50,6 +50,11 @@
<groupId>org.onosproject</groupId>
<artifactId>onlab-misc</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-core-serializers</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.pce.pcestore;
package org.onosproject.pcelabelstore;
import com.google.common.base.MoreObjects;
......@@ -21,8 +21,8 @@ import java.util.Objects;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import org.onosproject.pcelabelstore.api.LspLocalLabelInfo;
import org.onosproject.incubator.net.resource.label.LabelResourceId;
import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
/**
* Local node details including IN and OUT labels as well as IN and OUT port details.
......@@ -30,13 +30,9 @@ import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
public final class DefaultLspLocalLabelInfo implements LspLocalLabelInfo {
private final DeviceId deviceId;
private final LabelResourceId inLabelId;
private final LabelResourceId outLabelId;
private final PortNumber inPort;
private final PortNumber outPort;
/**
......@@ -152,15 +148,10 @@ public final class DefaultLspLocalLabelInfo implements LspLocalLabelInfo {
* Builder.
*/
public static final class Builder implements LspLocalLabelInfo.Builder {
private DeviceId deviceId;
private LabelResourceId inLabelId;
private LabelResourceId outLabelId;
private PortNumber inPort;
private PortNumber outPort;
/**
......
/*
* 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.pcelabelstore;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
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.util.KryoNamespace;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.incubator.net.resource.label.LabelResource;
import org.onosproject.incubator.net.resource.label.LabelResourceId;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.pcelabelstore.api.LspLocalLabelInfo;
import org.onosproject.pcelabelstore.api.PceLabelStore;
import org.onosproject.store.serializers.KryoNamespaces;
import org.onosproject.store.service.ConsistentMap;
import org.onosproject.store.service.Serializer;
import org.onosproject.store.service.StorageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Manages the pool of available labels to devices, links and tunnels.
*/
@Component(immediate = true)
@Service
public class DistributedPceLabelStore implements PceLabelStore {
private static final String DEVICE_ID_NULL = "Device ID cannot be null";
private static final String LABEL_RESOURCE_ID_NULL = "Label Resource Id cannot be null";
private static final String LINK_NULL = "LINK cannot be null";
private static final String PCECC_TUNNEL_INFO_NULL = "PCECC Tunnel Info cannot be null";
private static final String TUNNEL_ID_NULL = "Tunnel Id cannot be null";
private final Logger log = LoggerFactory.getLogger(getClass());
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected StorageService storageService;
// Mapping device with global node label
private ConsistentMap<DeviceId, LabelResourceId> globalNodeLabelMap;
// Mapping link with adjacency label
private ConsistentMap<Link, LabelResourceId> adjLabelMap;
// Mapping tunnel id with local labels.
private ConsistentMap<TunnelId, List<LspLocalLabelInfo>> tunnelLabelInfoMap;
// Locally maintain LSRID to device id mapping for better performance.
private Map<String, DeviceId> lsrIdDeviceIdMap = new HashMap<>();
// List of PCC LSR ids whose BGP device information was not available to perform
// label db sync.
private HashSet<DeviceId> pendinglabelDbSyncPccMap = new HashSet<>();
@Activate
protected void activate() {
globalNodeLabelMap = storageService.<DeviceId, LabelResourceId>consistentMapBuilder()
.withName("onos-pce-globalnodelabelmap")
.withSerializer(Serializer.using(
new KryoNamespace.Builder()
.register(KryoNamespaces.API)
.register(LabelResourceId.class)
.build()))
.build();
adjLabelMap = storageService.<Link, LabelResourceId>consistentMapBuilder()
.withName("onos-pce-adjlabelmap")
.withSerializer(Serializer.using(
new KryoNamespace.Builder()
.register(KryoNamespaces.API)
.register(Link.class,
LabelResource.class,
LabelResourceId.class)
.build()))
.build();
tunnelLabelInfoMap = storageService.<TunnelId, List<LspLocalLabelInfo>>consistentMapBuilder()
.withName("onos-pce-tunnellabelinfomap")
.withSerializer(Serializer.using(
new KryoNamespace.Builder()
.register(KryoNamespaces.API)
.register(TunnelId.class,
DefaultLspLocalLabelInfo.class,
LabelResourceId.class,
DeviceId.class)
.build()))
.build();
log.info("Started");
}
@Deactivate
protected void deactivate() {
log.info("Stopped");
}
@Override
public boolean existsGlobalNodeLabel(DeviceId id) {
checkNotNull(id, DEVICE_ID_NULL);
return globalNodeLabelMap.containsKey(id);
}
@Override
public boolean existsAdjLabel(Link link) {
checkNotNull(link, LINK_NULL);
return adjLabelMap.containsKey(link);
}
@Override
public boolean existsTunnelInfo(TunnelId tunnelId) {
checkNotNull(tunnelId, TUNNEL_ID_NULL);
return tunnelLabelInfoMap.containsKey(tunnelId);
}
@Override
public int getGlobalNodeLabelCount() {
return globalNodeLabelMap.size();
}
@Override
public int getAdjLabelCount() {
return adjLabelMap.size();
}
@Override
public int getTunnelInfoCount() {
return tunnelLabelInfoMap.size();
}
@Override
public Map<DeviceId, LabelResourceId> getGlobalNodeLabels() {
return globalNodeLabelMap.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().value()));
}
@Override
public Map<Link, LabelResourceId> getAdjLabels() {
return adjLabelMap.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().value()));
}
@Override
public Map<TunnelId, List<LspLocalLabelInfo>> getTunnelInfos() {
return tunnelLabelInfoMap.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().value()));
}
@Override
public LabelResourceId getGlobalNodeLabel(DeviceId id) {
checkNotNull(id, DEVICE_ID_NULL);
return globalNodeLabelMap.get(id) == null ? null : globalNodeLabelMap.get(id).value();
}
@Override
public LabelResourceId getAdjLabel(Link link) {
checkNotNull(link, LINK_NULL);
return adjLabelMap.get(link) == null ? null : adjLabelMap.get(link).value();
}
@Override
public List<LspLocalLabelInfo> getTunnelInfo(TunnelId tunnelId) {
checkNotNull(tunnelId, TUNNEL_ID_NULL);
return tunnelLabelInfoMap.get(tunnelId) == null ? null : tunnelLabelInfoMap.get(tunnelId).value();
}
@Override
public void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId) {
checkNotNull(deviceId, DEVICE_ID_NULL);
checkNotNull(labelId, LABEL_RESOURCE_ID_NULL);
globalNodeLabelMap.put(deviceId, labelId);
}
@Override
public void addAdjLabel(Link link, LabelResourceId labelId) {
checkNotNull(link, LINK_NULL);
checkNotNull(labelId, LABEL_RESOURCE_ID_NULL);
adjLabelMap.put(link, labelId);
}
@Override
public void addTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList) {
checkNotNull(tunnelId, TUNNEL_ID_NULL);
checkNotNull(lspLocalLabelInfoList, PCECC_TUNNEL_INFO_NULL);
tunnelLabelInfoMap.put(tunnelId, lspLocalLabelInfoList);
}
@Override
public boolean removeGlobalNodeLabel(DeviceId id) {
checkNotNull(id, DEVICE_ID_NULL);
if (globalNodeLabelMap.remove(id) == null) {
log.error("SR-TE node label deletion for device {} has failed.", id.toString());
return false;
}
return true;
}
@Override
public boolean removeAdjLabel(Link link) {
checkNotNull(link, LINK_NULL);
if (adjLabelMap.remove(link) == null) {
log.error("Adjacency label deletion for link {} hash failed.", link.toString());
return false;
}
return true;
}
@Override
public boolean removeTunnelInfo(TunnelId tunnelId) {
checkNotNull(tunnelId, TUNNEL_ID_NULL);
if (tunnelLabelInfoMap.remove(tunnelId) == null) {
log.error("Tunnel info deletion for tunnel id {} has failed.", tunnelId.toString());
return false;
}
return true;
}
@Override
public boolean addLsrIdDevice(String lsrId, DeviceId deviceId) {
checkNotNull(lsrId);
checkNotNull(deviceId);
lsrIdDeviceIdMap.put(lsrId, deviceId);
return true;
}
@Override
public boolean removeLsrIdDevice(String lsrId) {
checkNotNull(lsrId);
lsrIdDeviceIdMap.remove(lsrId);
return true;
}
@Override
public DeviceId getLsrIdDevice(String lsrId) {
checkNotNull(lsrId);
return lsrIdDeviceIdMap.get(lsrId);
}
@Override
public boolean addPccLsr(DeviceId lsrId) {
checkNotNull(lsrId);
pendinglabelDbSyncPccMap.add(lsrId);
return true;
}
@Override
public boolean removePccLsr(DeviceId lsrId) {
checkNotNull(lsrId);
pendinglabelDbSyncPccMap.remove(lsrId);
return true;
}
@Override
public boolean hasPccLsr(DeviceId lsrId) {
checkNotNull(lsrId);
return pendinglabelDbSyncPccMap.contains(lsrId);
}
}
package org.onosproject.pcelabelstore;
/**
* Representation of label operation over PCEP.
*/
public enum PcepLabelOp {
/**
* Signifies that the label operation is addition.
*/
ADD,
/**
* Signifies that the label operation is modification. This is reserved for future.
*/
MODIFY,
/**
* Signifies that the label operation is deletion.
*/
REMOVE
}
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.pce.pcestore.api;
package org.onosproject.pcelabelstore.api;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
......
/*
* 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.pcelabelstore.api;
import java.util.List;
import org.onosproject.incubator.net.resource.label.LabelResourceId;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import java.util.Map;
/**
* Abstraction of an entity providing pool of available labels to devices, links and tunnels.
*/
public interface PceLabelStore {
/**
* Checks whether device id is present in global node label store.
*
* @param id device id
* @return success of failure
*/
boolean existsGlobalNodeLabel(DeviceId id);
/**
* Checks whether link is present in adjacency label store.
*
* @param link link between devices
* @return success of failure
*/
boolean existsAdjLabel(Link link);
/**
* Checks whether tunnel id is present in tunnel info store.
*
* @param tunnelId tunnel id
* @return success of failure
*/
boolean existsTunnelInfo(TunnelId tunnelId);
/**
* Retrieves the node label count.
*
* @return node label count
*/
int getGlobalNodeLabelCount();
/**
* Retrieves the adjacency label count.
*
* @return adjacency label count
*/
int getAdjLabelCount();
/**
* Retrieves the tunnel info count.
*
* @return tunnel info count
*/
int getTunnelInfoCount();
/**
* Retrieves device id and label pairs collection from global node label store.
*
* @return collection of device id and label pairs
*/
Map<DeviceId, LabelResourceId> getGlobalNodeLabels();
/**
* Retrieves link and label pairs collection from adjacency label store.
*
* @return collection of link and label pairs
*/
Map<Link, LabelResourceId> getAdjLabels();
/**
* Retrieves tunnel id and pcecc tunnel info pairs collection from tunnel info store.
*
* @return collection of tunnel id and pcecc tunnel info pairs
*/
Map<TunnelId, List<LspLocalLabelInfo>> getTunnelInfos();
/**
* Retrieves node label for specified device id.
*
* @param id device id
* @return node label
*/
LabelResourceId getGlobalNodeLabel(DeviceId id);
/**
* Retrieves adjacency label for specified link.
*
* @param link between devices
* @return adjacency label
*/
LabelResourceId getAdjLabel(Link link);
/**
* Retrieves local label info with tunnel consumer id from tunnel info store.
*
* @param tunnelId tunnel id
* @return pcecc tunnel info
*/
List<LspLocalLabelInfo> getTunnelInfo(TunnelId tunnelId);
/**
* Stores node label into global node label store.
*
* @param deviceId device id
* @param labelId node label id
*/
void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId);
/**
* Stores adjacency label into adjacency label store.
*
* @param link link between nodes
* @param labelId link label id
*/
void addAdjLabel(Link link, LabelResourceId labelId);
/**
* Stores local label info with tunnel consumer id into tunnel info store for specified tunnel id.
*
* @param tunnelId tunnel id
* @param lspLocalLabelInfoList local label info
*/
void addTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList);
/**
* Removes device label from global node label store for specified device id.
*
* @param id device id
* @return success or failure
*/
boolean removeGlobalNodeLabel(DeviceId id);
/**
* Removes adjacency label from adjacency label store for specified link information.
*
* @param link between nodes
* @return success or failure
*/
boolean removeAdjLabel(Link link);
/**
* Removes local label info with tunnel consumer id from tunnel info store for specified tunnel id.
*
* @param tunnelId tunnel id
* @return success or failure
*/
boolean removeTunnelInfo(TunnelId tunnelId);
/**
* Adds lsrid to device id mapping.
*
* @param lsrId lsrId of the device
* @param deviceId device id
* @return success or failure
*/
boolean addLsrIdDevice(String lsrId, DeviceId deviceId);
/**
* Removes lsrid to device id mapping.
*
* @param lsrId lsrId of the device
* @return success or failure
*/
boolean removeLsrIdDevice(String lsrId);
/**
* Gets lsrid to device id mapping.
*
* @param lsrId lsrId of the device
* @return device id of the lsrId
*/
DeviceId getLsrIdDevice(String lsrId);
/**
* Adds lsrId of the PCC in form of device id for the PCC for which sync is pending due to non-availability of BGP.
* device.
*
* @param lsrId LSR id of the PCC in form of device id
* @return success or failure
*/
public boolean addPccLsr(DeviceId lsrId);
/**
* Removes lsrId of the PCC in form of device id for the PCC for which pending sync is done.
*
* @param lsrId LSR id of the PCC in form of device id
* @return success or failure
*/
public boolean removePccLsr(DeviceId lsrId);
/**
* Gets lsrId of the PCC in form of device id.
*
* @param lsrId LSR id of the PCC in form of device id
* @return success or failure
*/
public boolean hasPccLsr(DeviceId lsrId);
}
......@@ -13,7 +13,8 @@
* 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.
* PCE store service API.
*/
package org.onosproject.provider.pcep.packet.impl;
\ No newline at end of file
package org.onosproject.pcelabelstore.api;
......
......@@ -13,10 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.pcep.controller;
public interface PcepPacketListener {
void sendPacketIn(PccId pccId);
}
/**
* PCE store application.
*/
package org.onosproject.pcelabelstore;
......
/*
* 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.pcep.controller.impl;
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.Ip4Address;
import org.onlab.packet.IpAddress;
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.IpTunnelEndPoint;
import org.onosproject.incubator.net.tunnel.Tunnel;
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.pcelabelstore.DefaultLspLocalLabelInfo;
import org.onosproject.pcelabelstore.PcepLabelOp;
import org.onosproject.pcelabelstore.api.LspLocalLabelInfo;
import org.onosproject.pcelabelstore.api.PceLabelStore;
import org.onosproject.pcep.controller.LspType;
import org.onosproject.pcep.controller.PccId;
import org.onosproject.pcep.controller.PcepAnnotationKeys;
import org.onosproject.pcep.controller.PcepClient;
import org.onosproject.pcep.controller.PcepClientController;
import org.onosproject.pcep.controller.SrpIdGenerators;
import org.onosproject.pcepio.exceptions.PcepParseException;
import org.onosproject.pcepio.protocol.PcepAttribute;
import org.onosproject.pcepio.protocol.PcepBandwidthObject;
import org.onosproject.pcepio.protocol.PcepEroObject;
import org.onosproject.pcepio.protocol.PcepLabelObject;
import org.onosproject.pcepio.protocol.PcepLabelUpdate;
import org.onosproject.pcepio.protocol.PcepLabelUpdateMsg;
import org.onosproject.pcepio.protocol.PcepLspObject;
import org.onosproject.pcepio.protocol.PcepMsgPath;
import org.onosproject.pcepio.protocol.PcepSrpObject;
import org.onosproject.pcepio.protocol.PcepUpdateMsg;
import org.onosproject.pcepio.protocol.PcepUpdateRequest;
import org.onosproject.pcepio.types.IPv4SubObject;
import org.onosproject.pcepio.types.NexthopIPv4addressTlv;
import org.onosproject.pcepio.types.PathSetupTypeTlv;
import org.onosproject.pcepio.types.PcepLabelDownload;
import org.onosproject.pcepio.types.PcepValueType;
import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
import org.onosproject.pcepio.types.SymbolicPathNameTlv;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import static org.onosproject.pcep.controller.PcepAnnotationKeys.BANDWIDTH;
import static org.onosproject.pcep.controller.PcepAnnotationKeys.LSP_SIG_TYPE;
import static org.onosproject.pcep.controller.PcepAnnotationKeys.PCE_INIT;
import static org.onosproject.pcep.controller.PcepAnnotationKeys.DELEGATE;
/**
* 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);
public static final int OUT_LABEL_TYPE = 0;
public static final int IN_LABEL_TYPE = 1;
public static final long IDENTIFIER_SET = 0x100000000L;
public static final long SET = 0xFFFFFFFFL;
private static final String LSRID = "lsrId";
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 DeviceService deviceService;
private PceLabelStore pceStore;
private PcepClientController clientController;
private PcepLabelObject labelObj;
/**
* 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 pceStore pce label store
*/
public void initialize(LabelResourceService labelRsrcService,
DeviceService deviceService,
PceLabelStore pceStore,
PcepClientController clientController) {
this.labelRsrcService = labelRsrcService;
this.deviceService = deviceService;
this.pceStore = pceStore;
this.clientController = clientController;
}
/**
* 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;
}
try {
// Push into destination device
// Destination device IN port is link.dst().port()
pushLocalLabels(dstDeviceId, labelId, dstPort, tunnel, false,
Long.valueOf(LabelType.IN_LABEL.value), PcepLabelOp.ADD);
// Push into source device
// Source device OUT port will be link.dst().port(). Means its remote port used to send packet.
pushLocalLabels(srcDeviceId, labelId, dstPort, tunnel, isLastLabelToPush,
Long.valueOf(LabelType.OUT_LABEL.value), PcepLabelOp.ADD);
} catch (PcepParseException e) {
log.error("Failed to push local label for device {} or {} for tunnel {}.",
dstDeviceId.toString(), srcDeviceId.toString(), tunnel.tunnelName().toString());
}
// Add or update pcecc tunnel info in pce store.
updatePceccTunnelInfoInStore(srcDeviceId, dstDeviceId, labelId, dstPort,
tunnel);
} 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
*/
public void updatePceccTunnelInfoInStore(DeviceId srcDeviceId, DeviceId dstDeviceId, LabelResourceId labelId,
PortNumber dstPort, Tunnel tunnel) {
// 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;
List<LspLocalLabelInfo> lspLabelInfoList = pceStore.getTunnelInfo(tunnel.tunnelId());
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 (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);
}
pceStore.addTunnelInfo(tunnel.tunnelId(), lspLabelInfoList);
}
}
/**
* 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();
List<LspLocalLabelInfo> lspLocalLabelInfoList = pceStore.getTunnelInfo(tunnel.tunnelId());
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();
try {
// Push into device
if ((outLabelId != null) && (outPort != null)) {
pushLocalLabels(deviceId, outLabelId, outPort, tunnel, false,
Long.valueOf(LabelType.OUT_LABEL.value), PcepLabelOp.REMOVE);
}
if ((inLabelId != null) && (inPort != null)) {
pushLocalLabels(deviceId, inLabelId, inPort, tunnel, false,
Long.valueOf(LabelType.IN_LABEL.value), PcepLabelOp.REMOVE);
}
} catch (PcepParseException e) {
log.error("Failed to push local label for device {}for tunnel {}.", deviceId.toString(),
tunnel.tunnelName().toString());
}
// 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);
}
pceStore.removeTunnelInfo(tunnel.tunnelId());
}
//Pushes local labels to the device which is specific to path [CR-case].
private void pushLocalLabels(DeviceId deviceId, LabelResourceId labelId,
PortNumber portNum, Tunnel tunnel,
Boolean isBos, Long labelType, PcepLabelOp type) throws PcepParseException {
checkNotNull(deviceId);
checkNotNull(labelId);
checkNotNull(portNum);
checkNotNull(tunnel);
checkNotNull(labelType);
checkNotNull(type);
PcepClient pc = getPcepClient(deviceId);
if (pc == null) {
log.error("PCEP client not found");
return;
}
PcepLspObject lspObj;
LinkedList<PcepLabelUpdate> labelUpdateList = new LinkedList<>();
LinkedList<PcepLabelObject> labelObjects = new LinkedList<>();
PcepSrpObject srpObj;
PcepLabelDownload labelDownload = new PcepLabelDownload();
LinkedList<PcepValueType> optionalTlv = new LinkedList<>();
long portNo = portNum.toLong();
portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo;
optionalTlv.add(NexthopIPv4addressTlv.of((int) portNo));
PcepLabelObject labelObj = pc.factory().buildLabelObject()
.setOFlag(labelType == OUT_LABEL_TYPE ? true : false)
.setOptionalTlv(optionalTlv)
.setLabel((int) labelId.labelId())
.build();
/**
* Check whether transit node or not. For transit node, label update message should include IN and OUT labels.
* Hence store IN label object and next when out label comes add IN and OUT label objects and encode label
* update message and send to specified client.
*/
if (!deviceId.equals(tunnel.path().src().deviceId()) && !deviceId.equals(tunnel.path().dst().deviceId())) {
//Device is transit node
if (labelType == OUT_LABEL_TYPE) {
//Store label object having IN label value
this.labelObj = labelObj;
return;
}
//Add IN label object
labelObjects.add(this.labelObj);
}
//Add OUT label object in case of transit node
labelObjects.add(labelObj);
srpObj = getSrpObject(pc, type, false);
String lspId = tunnel.annotations().value(PcepAnnotationKeys.LOCAL_LSP_ID);
String plspId = tunnel.annotations().value(PcepAnnotationKeys.PLSP_ID);
String tunnelIdentifier = tunnel.annotations().value(PcepAnnotationKeys.PCC_TUNNEL_ID);
LinkedList<PcepValueType> tlvs = new LinkedList<>();
StatefulIPv4LspIdentifiersTlv lspIdTlv = new StatefulIPv4LspIdentifiersTlv(((IpTunnelEndPoint) tunnel.src())
.ip().getIp4Address().toInt(), Short.valueOf(lspId), Short.valueOf(tunnelIdentifier),
((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt(),
((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt());
tlvs.add(lspIdTlv);
if (tunnel.tunnelName().value() != null) {
SymbolicPathNameTlv pathNameTlv = new SymbolicPathNameTlv(tunnel.tunnelName().value().getBytes());
tlvs.add(pathNameTlv);
}
boolean delegated = (tunnel.annotations().value(DELEGATE) == null) ? false
: Boolean.valueOf(tunnel.annotations()
.value(DELEGATE));
boolean initiated = (tunnel.annotations().value(PCE_INIT) == null) ? false
: Boolean.valueOf(tunnel.annotations()
.value(PCE_INIT));
lspObj = pc.factory().buildLspObject()
.setRFlag(false)
.setAFlag(true)
.setDFlag(delegated)
.setCFlag(initiated)
.setPlspId(Integer.valueOf(plspId))
.setOptionalTlv(tlvs)
.build();
labelDownload.setLabelList(labelObjects);
labelDownload.setLspObject(lspObj);
labelDownload.setSrpObject(srpObj);
labelUpdateList.add(pc.factory().buildPcepLabelUpdateObject()
.setLabelDownload(labelDownload)
.build());
PcepLabelUpdateMsg labelMsg = pc.factory().buildPcepLabelUpdateMsg()
.setPcLabelUpdateList(labelUpdateList)
.build();
pc.sendMessage(labelMsg);
//If isBos is true, label download is done along the LSP, send PCEP update message.
if (isBos) {
sendPcepUpdateMsg(pc, lspObj, tunnel);
}
}
//Sends PCEP update message.
private void sendPcepUpdateMsg(PcepClient pc, PcepLspObject lspObj, Tunnel tunnel) throws PcepParseException {
LinkedList<PcepUpdateRequest> updateRequestList = new LinkedList<>();
LinkedList<PcepValueType> subObjects = createEroSubObj(tunnel.path());
if (subObjects == null) {
log.error("ERO subjects not present");
return;
}
// set PathSetupTypeTlv of SRP object
LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
LspType lspSigType = LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE));
llOptionalTlv.add(new PathSetupTypeTlv(lspSigType.type()));
PcepSrpObject srpObj = pc.factory().buildSrpObject()
.setRFlag(false)
.setSrpID(SrpIdGenerators.create())
.setOptionalTlv(llOptionalTlv)
.build();
PcepEroObject eroObj = pc.factory().buildEroObject()
.setSubObjects(subObjects)
.build();
float iBandwidth = 0;
if (tunnel.annotations().value(BANDWIDTH) != null) {
//iBandwidth = Float.floatToIntBits(Float.parseFloat(tunnel.annotations().value(BANDWIDTH)));
iBandwidth = Float.parseFloat(tunnel.annotations().value(BANDWIDTH));
}
// build bandwidth object
PcepBandwidthObject bandwidthObject = pc.factory().buildBandwidthObject()
.setBandwidth(iBandwidth)
.build();
// build pcep attribute
PcepAttribute pcepAttribute = pc.factory().buildPcepAttribute()
.setBandwidthObject(bandwidthObject)
.build();
PcepMsgPath msgPath = pc.factory().buildPcepMsgPath()
.setEroObject(eroObj)
.setPcepAttribute(pcepAttribute)
.build();
PcepUpdateRequest updateReq = pc.factory().buildPcepUpdateRequest()
.setSrpObject(srpObj)
.setMsgPath(msgPath)
.setLspObject(lspObj)
.build();
updateRequestList.add(updateReq);
//TODO: P = 1 is it P flag in PCEP obj header
PcepUpdateMsg updateMsg = pc.factory().buildUpdateMsg()
.setUpdateRequestList(updateRequestList)
.build();
pc.sendMessage(updateMsg);
}
private LinkedList<PcepValueType> createEroSubObj(Path path) {
LinkedList<PcepValueType> subObjects = new LinkedList<>();
List<Link> links = path.links();
ConnectPoint source = null;
ConnectPoint destination = null;
IpAddress ipDstAddress = null;
IpAddress ipSrcAddress = null;
PcepValueType subObj = null;
long portNo;
for (Link link : links) {
source = link.src();
if (!(source.equals(destination))) {
//set IPv4SubObject for ERO object
portNo = source.port().toLong();
portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo;
ipSrcAddress = Ip4Address.valueOf((int) portNo);
subObj = new IPv4SubObject(ipSrcAddress.getIp4Address().toInt());
subObjects.add(subObj);
}
destination = link.dst();
portNo = destination.port().toLong();
portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo;
ipDstAddress = Ip4Address.valueOf((int) portNo);
subObj = new IPv4SubObject(ipDstAddress.getIp4Address().toInt());
subObjects.add(subObj);
}
return subObjects;
}
private PcepSrpObject getSrpObject(PcepClient pc, PcepLabelOp type, boolean bSFlag)
throws PcepParseException {
PcepSrpObject srpObj;
boolean bRFlag = false;
if (!type.equals(PcepLabelOp.ADD)) {
// To cleanup labels, R bit is set
bRFlag = true;
}
srpObj = pc.factory().buildSrpObject()
.setRFlag(bRFlag)
.setSFlag(bSFlag)
.setSrpID(SrpIdGenerators.create())
.build();
return srpObj;
}
/**
* Returns PCEP client.
*
* @return PCEP client
*/
private PcepClient getPcepClient(DeviceId deviceId) {
Device device = deviceService.getDevice(deviceId);
// In future projections instead of annotations will be used to fetch LSR ID.
String lsrId = device.annotations().value(LSRID);
PcepClient pcc = clientController.getClient(PccId.pccId(IpAddress.valueOf(lsrId)));
return pcc;
}
}
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.onosproject.pce.pceservice;
package org.onosproject.pcep.controller.impl;
/**
* Describes about Label type.
......
......@@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.pce.pceservice;
package org.onosproject.pcep.controller.impl;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.pcep.controller.PcepSyncStatus.IN_SYNC;
import static org.onosproject.pcep.controller.PcepSyncStatus.SYNCED;
import java.util.Collection;
import java.util.Iterator;
......@@ -26,9 +28,6 @@ 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;
......@@ -37,20 +36,24 @@ 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.pcelabelstore.PcepLabelOp;
import org.onosproject.pcelabelstore.api.PceLabelStore;
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.onosproject.pcep.controller.PccId;
import org.onosproject.pcep.controller.PcepClient;
import org.onosproject.pcep.controller.PcepClientController;
import org.onosproject.pcep.controller.SrpIdGenerators;
import org.onosproject.pcepio.exceptions.PcepParseException;
import org.onosproject.pcepio.protocol.PcepFecObjectIPv4;
import org.onosproject.pcepio.protocol.PcepFecObjectIPv4Adjacency;
import org.onosproject.pcepio.protocol.PcepLabelObject;
import org.onosproject.pcepio.protocol.PcepLabelUpdate;
import org.onosproject.pcepio.protocol.PcepLabelUpdateMsg;
import org.onosproject.pcepio.protocol.PcepSrpObject;
import org.onosproject.pcepio.types.PcepLabelMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -75,14 +78,12 @@ public final class PceccSrTeBeHandler {
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;
private PcepClientController clientController;
private PceLabelStore pceStore;
/**
* Initializes default values.
......@@ -107,19 +108,18 @@ public final class PceccSrTeBeHandler {
*
* @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,
public void initialize(LabelResourceAdminService labelRsrcAdminService,
LabelResourceService labelRsrcService,
PcepClientController clientController,
PceLabelStore pceStore,
DeviceService deviceService) {
this.labelRsrcAdminService = labelRsrcAdminService;
this.labelRsrcService = labelRsrcService;
this.flowObjectiveService = flowObjectiveService;
this.clientController = clientController;
this.pceStore = pceStore;
this.appId = appId;
this.deviceService = deviceService;
}
......@@ -208,14 +208,20 @@ public final class PceccSrTeBeHandler {
pceStore.addGlobalNodeLabel(specificDeviceId, specificLabelId);
// Push its label information into specificDeviceId
advertiseNodeLabelRule(specificDeviceId, specificLabelId,
IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH),
Objective.Operation.ADD, false);
PcepClient pcc = getPcepClient(specificDeviceId);
try {
pushGlobalNodeLabel(pcc,
specificLabelId,
IpAddress.valueOf(specificLsrId).getIp4Address().toInt(),
PcepLabelOp.ADD,
false);
} catch (PcepParseException e) {
log.error("Failed to push global node label for LSR {}.", specificLsrId.toString());
}
// 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);
......@@ -228,16 +234,23 @@ public final class PceccSrTeBeHandler {
// 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);
try {
pushGlobalNodeLabel(getPcepClient(otherDevId),
specificLabelId,
IpAddress.valueOf(specificLsrId).getIp4Address().toInt(),
PcepLabelOp.ADD,
false);
advertiseNodeLabelRule(specificDeviceId, otherLabelId,
IpPrefix.valueOf(IpAddress.valueOf(otherLsrId), PREFIX_LENGTH),
Objective.Operation.ADD, false);
pushGlobalNodeLabel(pcc, specificLabelId,
IpAddress.valueOf(otherLsrId).getIp4Address().toInt(),
PcepLabelOp.ADD,
false);
} catch (PcepParseException e) {
log.error("Failed to push global node label for LSR {} or LSR {}.", specificLsrId.toString(),
otherLsrId.toString());
}
}
}
return true;
}
......@@ -271,9 +284,15 @@ public final class PceccSrTeBeHandler {
// 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);
try {
pushGlobalNodeLabel(getPcepClient(otherDevId),
labelId,
IpAddress.valueOf(specificLsrId).getIp4Address().toInt(),
PcepLabelOp.REMOVE,
false);
} catch (PcepParseException e) {
log.error("Failed to push global node label for LSR {}.", specificLsrId.toString());
}
}
}
......@@ -290,7 +309,6 @@ public final class PceccSrTeBeHandler {
log.error("Unable to remove global node label id {} from store.", labelId.toString());
retValue = false;
}
return retValue;
}
......@@ -335,7 +353,13 @@ public final class PceccSrTeBeHandler {
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);
try {
pushAdjacencyLabel(getPcepClient(srcDeviceId), labelId, (int) link.src().port().toLong(),
(int) link.dst().port().toLong(), PcepLabelOp.ADD);
} catch (PcepParseException e) {
log.error("Failed to push adjacency label for link {}-{}.", (int) link.src().port().toLong(),
(int) link.dst().port().toLong());
}
// Save in store
pceStore.addAdjLabel(link, labelId);
......@@ -365,7 +389,14 @@ public final class PceccSrTeBeHandler {
DeviceId srcDeviceId = link.src().deviceId();
// Release adjacency label from device
installAdjLabelRule(srcDeviceId, labelId, link.src().port(), link.dst().port(), Objective.Operation.REMOVE);
try {
pushAdjacencyLabel(getPcepClient(srcDeviceId), labelId, (int) link.src().port().toLong(),
(int) link.dst().port().toLong(), PcepLabelOp.REMOVE);
} catch (PcepParseException e) {
log.error("Failed to push adjacency label for link {}-{}.", (int) link.src().port().toLong(),
(int) link.dst().port().toLong());
}
// Release link label from label manager
Multimap<DeviceId, LabelResource> release = ArrayListMultimap.create();
......@@ -429,98 +460,125 @@ public final class PceccSrTeBeHandler {
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();
//Pushes node labels to the specified device.
void pushGlobalNodeLabel(PcepClient pc, LabelResourceId labelId,
int labelForNode, PcepLabelOp type, boolean isBos) throws PcepParseException {
selectorBuilder.matchMplsLabel(MplsLabel.mplsLabel(labelId.id().intValue()));
checkNotNull(pc);
checkNotNull(labelId);
checkNotNull(type);
TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
LinkedList<PcepLabelUpdate> labelUpdateList = new LinkedList<>();
PcepFecObjectIPv4 fecObject = pc.factory().buildFecObjectIpv4()
.setNodeID(labelForNode)
.build();
ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder()
.withSelector(selectorBuilder.build()).withTreatment(treatment)
.withFlag(ForwardingObjective.Flag.VERSATILE).fromApp(appId).makePermanent();
boolean bSFlag = false;
if (pc.labelDbSyncStatus() == IN_SYNC && !isBos) {
// Need to set sync flag in all messages till sync completes.
bSFlag = true;
}
if (type.equals(Objective.Operation.ADD)) {
PcepSrpObject srpObj = getSrpObject(pc, type, bSFlag);
flowObjectiveService.forward(deviceId, forwardingObjective.add());
} else {
flowObjectiveService.forward(deviceId, forwardingObjective.remove());
//Global NODE-SID as label object
PcepLabelObject labelObject = pc.factory().buildLabelObject()
.setLabel((int) labelId.labelId())
.build();
PcepLabelMap labelMap = new PcepLabelMap();
labelMap.setFecObject(fecObject);
labelMap.setLabelObject(labelObject);
labelMap.setSrpObject(srpObj);
labelUpdateList.add(pc.factory().buildPcepLabelUpdateObject()
.setLabelMap(labelMap)
.build());
PcepLabelUpdateMsg labelMsg = pc.factory().buildPcepLabelUpdateMsg()
.setPcLabelUpdateList(labelUpdateList)
.build();
pc.sendMessage(labelMsg);
if (isBos) {
// Sync is completed.
pc.setLabelDbSyncStatus(SYNCED);
}
}
/**
* 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();
//Pushes adjacency labels to the specified device.
void pushAdjacencyLabel(PcepClient pc, LabelResourceId labelId, int srcPortNo,
int dstPortNo, PcepLabelOp type)
throws PcepParseException {
checkNotNull(pc);
checkNotNull(labelId);
checkNotNull(type);
selectorBuilder.matchMplsLabel(MplsLabel.mplsLabel(labelId.id().intValue()));
selectorBuilder.matchIPSrc(ipPrefix);
LinkedList<PcepLabelUpdate> labelUpdateList = new LinkedList<>();
PcepFecObjectIPv4Adjacency fecAdjObject = pc.factory().buildFecIpv4Adjacency()
.seRemoteIPv4Address(dstPortNo)
.seLocalIPv4Address(srcPortNo)
.build();
if (bBos) {
selectorBuilder.matchMplsBos(bBos);
boolean bSFlag = false;
if (pc.labelDbSyncStatus() == IN_SYNC) {
// Need to set sync flag in all messages till sync completes.
bSFlag = true;
}
TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
PcepSrpObject srpObj = getSrpObject(pc, type, bSFlag);
ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder()
.withSelector(selectorBuilder.build()).withTreatment(treatment)
.withFlag(ForwardingObjective.Flag.VERSATILE).fromApp(appId).makePermanent();
//Adjacency label object
PcepLabelObject labelObject = pc.factory().buildLabelObject()
.setLabel((int) labelId.labelId())
.build();
if (type.equals(Objective.Operation.ADD)) {
flowObjectiveService.forward(deviceId, forwardingObjective.add());
} else {
flowObjectiveService.forward(deviceId, forwardingObjective.remove());
PcepLabelMap labelMap = new PcepLabelMap();
labelMap.setFecObject(fecAdjObject);
labelMap.setLabelObject(labelObject);
labelMap.setSrpObject(srpObj);
labelUpdateList.add(pc.factory().buildPcepLabelUpdateObject()
.setLabelMap(labelMap)
.build());
PcepLabelUpdateMsg labelMsg = pc.factory().buildPcepLabelUpdateMsg()
.setPcLabelUpdateList(labelUpdateList)
.build();
pc.sendMessage(labelMsg);
}
private PcepSrpObject getSrpObject(PcepClient pc, PcepLabelOp type, boolean bSFlag)
throws PcepParseException {
PcepSrpObject srpObj;
boolean bRFlag = false;
if (!type.equals(PcepLabelOp.ADD)) {
// To cleanup labels, R bit is set
bRFlag = true;
}
srpObj = pc.factory().buildSrpObject()
.setRFlag(bRFlag)
.setSFlag(bSFlag)
.setSrpID(SrpIdGenerators.create())
.build();
return srpObj;
}
/**
* Install a rule for pushing Adjacency labels to the device.
* Returns PCEP client.
*
* @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
* @return PCEP client
*/
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();
private PcepClient getPcepClient(DeviceId deviceId) {
Device device = deviceService.getDevice(deviceId);
if (type.equals(Objective.Operation.ADD)) {
flowObjectiveService.forward(deviceId, forwardingObjective.add());
} else {
flowObjectiveService.forward(deviceId, forwardingObjective.remove());
}
// In future projections instead of annotations will be used to fetch LSR ID.
String lsrId = device.annotations().value(LSR_ID);
PcepClient pcc = clientController.getClient(PccId.pccId(IpAddress.valueOf(lsrId)));
return pcc;
}
}
......
......@@ -26,6 +26,7 @@ import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.felix.scr.annotations.Activate;
......@@ -34,12 +35,40 @@ 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.Ip4Address;
import org.onlab.packet.IpAddress;
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.incubator.net.tunnel.DefaultLabelStack;
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.TunnelService;
import org.onosproject.incubator.net.tunnel.Tunnel.State;
import org.onosproject.mastership.MastershipService;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultAnnotations.Builder;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.MastershipRole;
import org.onosproject.net.Path;
import org.onosproject.net.config.NetworkConfigEvent;
import org.onosproject.net.config.NetworkConfigListener;
import org.onosproject.net.config.NetworkConfigService;
import org.onosproject.net.device.DeviceEvent;
import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.link.LinkEvent;
import org.onosproject.net.link.LinkListener;
import org.onosproject.net.link.LinkService;
import org.onosproject.pcelabelstore.PcepLabelOp;
import org.onosproject.pcelabelstore.api.PceLabelStore;
import org.onosproject.pcep.api.DeviceCapability;
import org.onosproject.pcep.controller.LspKey;
import org.onosproject.pcep.controller.LspType;
import org.onosproject.pcep.controller.PccId;
import org.onosproject.pcep.controller.PcepClient;
import org.onosproject.pcep.controller.PcepClientController;
......@@ -47,8 +76,6 @@ import org.onosproject.pcep.controller.PcepClientListener;
import org.onosproject.pcep.controller.PcepEventListener;
import org.onosproject.pcep.controller.PcepLspStatus;
import org.onosproject.pcep.controller.PcepNodeListener;
import org.onosproject.pcep.controller.PcepPacketListener;
import org.onosproject.pcep.controller.PcepSyncStatus;
import org.onosproject.pcep.controller.SrpIdGenerators;
import org.onosproject.pcep.controller.driver.PcepAgent;
import org.onosproject.pcepio.exceptions.PcepParseException;
......@@ -61,10 +88,15 @@ import org.onosproject.pcepio.protocol.PcepFactory;
import org.onosproject.pcepio.protocol.PcepInitiateMsg;
import org.onosproject.pcepio.protocol.PcepLspObject;
import org.onosproject.pcepio.protocol.PcepMessage;
import org.onosproject.pcepio.protocol.PcepNai;
import org.onosproject.pcepio.protocol.PcepReportMsg;
import org.onosproject.pcepio.protocol.PcepSrpObject;
import org.onosproject.pcepio.protocol.PcepStateReport;
import org.onosproject.pcepio.types.PathSetupTypeTlv;
import org.onosproject.pcepio.types.PcepNaiIpv4Adjacency;
import org.onosproject.pcepio.types.PcepNaiIpv4NodeId;
import org.onosproject.pcepio.types.PcepValueType;
import org.onosproject.pcepio.types.SrEroSubObject;
import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
import org.onosproject.pcepio.types.SymbolicPathNameTlv;
import org.slf4j.Logger;
......@@ -74,11 +106,23 @@ import com.google.common.collect.Sets;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.pcep.controller.PcepSyncStatus.IN_SYNC;
import static org.onosproject.pcep.controller.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
import static org.onosproject.pcep.controller.LspType.WITH_SIGNALLING;
import static org.onosproject.pcep.controller.PcepLspSyncAction.REMOVE;
import static org.onosproject.pcep.controller.PcepLspSyncAction.SEND_UPDATE;
import static org.onosproject.pcep.controller.PcepLspSyncAction.UNSTABLE;
import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_TYPE_19;
import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_VALUE_5;
import static org.onosproject.pcep.controller.PcepAnnotationKeys.BANDWIDTH;
import static org.onosproject.pcep.controller.PcepAnnotationKeys.LOCAL_LSP_ID;
import static org.onosproject.pcep.controller.PcepAnnotationKeys.LSP_SIG_TYPE;
import static org.onosproject.pcep.controller.PcepAnnotationKeys.PCC_TUNNEL_ID;
import static org.onosproject.pcep.controller.PcepAnnotationKeys.PCE_INIT;
import static org.onosproject.pcep.controller.PcepAnnotationKeys.PLSP_ID;
import static org.onosproject.pcep.controller.PcepAnnotationKeys.DELEGATE;
import static org.onosproject.pcep.controller.PcepAnnotationKeys.COST_TYPE;
import static org.onosproject.pcep.controller.PcepSyncStatus.SYNCED;
import static org.onosproject.pcep.controller.PcepSyncStatus.NOT_SYNCED;
/**
* Implementation of PCEP client controller.
......@@ -88,10 +132,33 @@ import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_VALUE_5;
public class PcepClientControllerImpl implements PcepClientController {
private static final Logger log = LoggerFactory.getLogger(PcepClientControllerImpl.class);
private static final long IDENTIFIER_SET = 0x100000000L;
private static final long SET = 0xFFFFFFFFL;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceService deviceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected LinkService linkService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected TunnelService tunnelService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected NetworkConfigService netCfgService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected MastershipService mastershipService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected LabelResourceAdminService labelRsrcAdminService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected LabelResourceService labelRsrcService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected PceLabelStore pceStore;
protected ConcurrentHashMap<PccId, PcepClient> connectedClients =
new ConcurrentHashMap<>();
......@@ -100,25 +167,44 @@ public class PcepClientControllerImpl implements PcepClientController {
protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet();
protected Set<PcepNodeListener> pcepNodeListener = Sets.newHashSet();
protected Set<PcepPacketListener> pcepPacketListener = Sets.newHashSet();
// LSR-id and device-id mapping for checking capability if L3 device is not
// having its capability
private Map<String, DeviceId> lsrIdDeviceIdMap = new HashMap<>();
private final Controller ctrl = new Controller();
public static final long GLOBAL_LABEL_SPACE_MIN = 4097;
public static final long GLOBAL_LABEL_SPACE_MAX = 5121;
private static final String LSRID = "lsrId";
private static final String DEVICE_NULL = "Device-cannot be null";
private static final String LINK_NULL = "Link-cannot be null";
public static final String BANDWIDTH = "bandwidth";
public static final String LSP_SIG_TYPE = "lspSigType";
public static final String PCC_TUNNEL_ID = "PccTunnelId";
public static final String PLSP_ID = "PLspId";
public static final String LOCAL_LSP_ID = "localLspId";
public static final String PCE_INIT = "pceInit";
public static final String COST_TYPE = "costType";
public static final String DELEGATE = "delegation";
private BasicPceccHandler crHandler;
private PceccSrTeBeHandler srTeHandler;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected TunnelService tunnelService;
private DeviceListener deviceListener = new InternalDeviceListener();
private LinkListener linkListener = new InternalLinkListener();
private InternalConfigListener cfgListener = new InternalConfigListener();
@Activate
public void activate() {
ctrl.start(agent);
crHandler = BasicPceccHandler.getInstance();
crHandler.initialize(labelRsrcService, deviceService, pceStore, this);
srTeHandler = PceccSrTeBeHandler.getInstance();
srTeHandler.initialize(labelRsrcAdminService, labelRsrcService, this, pceStore,
deviceService);
deviceService.addListener(deviceListener);
linkService.addListener(linkListener);
netCfgService.addListener(cfgListener);
// 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");
}
......@@ -126,6 +212,9 @@ public class PcepClientControllerImpl implements PcepClientController {
public void deactivate() {
// Close all connected clients
closeConnectedClients();
deviceService.removeListener(deviceListener);
linkService.removeListener(linkListener);
netCfgService.removeListener(cfgListener);
ctrl.stop();
log.info("Stopped");
}
......@@ -163,16 +252,6 @@ public class PcepClientControllerImpl implements PcepClientController {
}
@Override
public void addPacketListener(PcepPacketListener listener) {
pcepPacketListener.add(listener);
}
@Override
public void removePacketListener(PcepPacketListener listener) {
pcepPacketListener.remove(listener);
}
@Override
public void writeMessage(PccId pccId, PcepMessage msg) {
this.getClient(pccId).sendMessage(msg);
}
......@@ -239,10 +318,10 @@ public class PcepClientControllerImpl implements PcepClientController {
PcepStateReport stateRpt = listIterator.next();
PcepLspObject lspObj = stateRpt.getLspObject();
if (lspObj.getSFlag()) {
if (pc.lspDbSyncStatus() != PcepSyncStatus.IN_SYNC) {
if (pc.lspDbSyncStatus() != IN_SYNC) {
log.debug("LSP DB sync started for PCC {}", pc.getPccId().id().toString());
// Initialize LSP DB sync and temporary cache.
pc.setLspDbSyncStatus(PcepSyncStatus.IN_SYNC);
pc.setLspDbSyncStatus(IN_SYNC);
pc.initializeSyncMsgList(pccId);
}
// Store stateRpt in temporary cache.
......@@ -251,18 +330,24 @@ public class PcepClientControllerImpl implements PcepClientController {
// Don't send to provider as of now.
continue;
} else if (lspObj.getPlspId() == 0) {
if (pc.lspDbSyncStatus() == PcepSyncStatus.IN_SYNC
|| pc.lspDbSyncStatus() == PcepSyncStatus.NOT_SYNCED) {
if (pc.lspDbSyncStatus() == IN_SYNC
|| pc.lspDbSyncStatus() == NOT_SYNCED) {
// Set end of LSPDB sync.
log.debug("LSP DB sync completed for PCC {}", pc.getPccId().id().toString());
pc.setLspDbSyncStatus(PcepSyncStatus.SYNCED);
pc.setLspDbSyncStatus(SYNCED);
// Call packet provider to initiate label DB sync (only if PCECC capable).
if (pc.capability().pceccCapability()) {
log.debug("Trigger label DB sync for PCC {}", pc.getPccId().id().toString());
pc.setLabelDbSyncStatus(IN_SYNC);
for (PcepPacketListener l : pcepPacketListener) {
l.sendPacketIn(pccId);
// Get lsrId of the PCEP client from the PCC ID. Session info is based on lsrID.
String lsrId = String.valueOf(pccId.ipAddress());
DeviceId pccDeviceId = DeviceId.deviceId(lsrId);
try {
syncLabelDb(pccDeviceId);
pc.setLabelDbSyncStatus(SYNCED);
} catch (PcepParseException e) {
log.error("Exception caught in sending label masg to PCC while in sync.");
}
} else {
// If label db sync is not to be done, handle end of LSPDB sync actions.
......@@ -272,6 +357,27 @@ public class PcepClientControllerImpl implements PcepClientController {
}
}
PcepLspStatus pcepLspStatus = PcepLspStatus.values()[lspObj.getOFlag()];
LspType lspType = getLspType(stateRpt.getSrpObject());
// Download (or remove) labels for basic PCECC LSPs.
if (lspType.equals(WITHOUT_SIGNALLING_AND_WITHOUT_SR)) {
boolean isRemove = lspObj.getRFlag();
Tunnel tunnel = null;
if (isRemove || pcepLspStatus.equals(PcepLspStatus.GOING_UP)) {
tunnel = getTunnel(lspObj);
}
if (tunnel != null) {
if (isRemove) {
crHandler.releaseLabel(tunnel);
} else {
crHandler.allocateLabel(tunnel);
}
}
}
// It's a usual report message while sync is not undergoing. So process it immediately.
LinkedList<PcepStateReport> llPcRptList = new LinkedList<>();
llPcRptList.add(stateRpt);
......@@ -300,6 +406,113 @@ public class PcepClientControllerImpl implements PcepClientController {
}
}
private LspType getLspType(PcepSrpObject srpObj) {
LspType lspType = WITH_SIGNALLING;
if (null != srpObj) {
LinkedList<PcepValueType> llOptionalTlv = srpObj.getOptionalTlv();
ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
while (listIterator.hasNext()) {
PcepValueType tlv = listIterator.next();
switch (tlv.getType()) {
case PathSetupTypeTlv.TYPE:
lspType = LspType.values()[Integer.valueOf(((PathSetupTypeTlv) tlv).getPst())];
break;
default:
break;
}
}
}
return lspType;
}
private Tunnel getTunnel(PcepLspObject lspObj) {
ListIterator<PcepValueType> listTlvIterator = lspObj.getOptionalTlv().listIterator();
StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv = null;
SymbolicPathNameTlv pathNameTlv = null;
Tunnel tunnel = null;
while (listTlvIterator.hasNext()) {
PcepValueType tlv = listTlvIterator.next();
switch (tlv.getType()) {
case StatefulIPv4LspIdentifiersTlv.TYPE:
ipv4LspIdenTlv = (StatefulIPv4LspIdentifiersTlv) tlv;
break;
case SymbolicPathNameTlv.TYPE:
pathNameTlv = (SymbolicPathNameTlv) tlv;
break;
default:
break;
}
}
/*
* Draft says: The LSP-IDENTIFIERS TLV MUST be included in the LSP object in PCRpt messages for
* RSVP-signaled LSPs. For ONOS PCECC implementation, it is mandatory.
*/
if (ipv4LspIdenTlv == null) {
log.error("Stateful IPv4 identifier TLV is null in PCRpt msg.");
return null;
}
IpTunnelEndPoint tunnelEndPointSrc = IpTunnelEndPoint
.ipTunnelPoint(IpAddress.valueOf(ipv4LspIdenTlv.getIpv4IngressAddress()));
IpTunnelEndPoint tunnelEndPointDst = IpTunnelEndPoint
.ipTunnelPoint(IpAddress.valueOf(ipv4LspIdenTlv.getIpv4EgressAddress()));
Collection<Tunnel> tunnelQueryResult = tunnelService.queryTunnel(tunnelEndPointSrc, tunnelEndPointDst);
for (Tunnel tunnelObj : tunnelQueryResult) {
if (tunnelObj.annotations().value(PLSP_ID) == null) {
/*
* PLSP_ID is null while Tunnel is created at PCE and PCInit msg carries it as 0. It is allocated by
* PCC and in that case it becomes the first PCRpt msg from PCC for this LSP, and hence symbolic
* path name must be carried in the PCRpt msg. Draft says: The SYMBOLIC-PATH-NAME TLV "MUST" be
* included in the LSP object in the LSP State Report (PCRpt) message when during a given PCEP
* session an LSP is "first" reported to a PCE.
*/
if ((pathNameTlv != null)
&& Arrays.equals(tunnelObj.tunnelName().value().getBytes(), pathNameTlv.getValue())) {
tunnel = tunnelObj;
break;
}
continue;
}
if ((Integer.valueOf(tunnelObj.annotations().value(PLSP_ID)) == lspObj.getPlspId())) {
if ((Integer
.valueOf(tunnelObj.annotations().value(LOCAL_LSP_ID)) == ipv4LspIdenTlv.getLspId())) {
tunnel = tunnelObj;
break;
}
}
}
if (tunnel == null || tunnel.annotations().value(PLSP_ID) != null) {
return tunnel;
}
// The returned tunnel is used just for filling values in Label message. So manipulate locally
// and return so that to allocate label, we don't need to wait for the tunnel in the "core"
// to be updated, as that depends on listener mechanism and there may be timing/multi-threading issues.
Builder annotationBuilder = DefaultAnnotations.builder();
annotationBuilder.set(BANDWIDTH, tunnel.annotations().value(BANDWIDTH));
annotationBuilder.set(COST_TYPE, tunnel.annotations().value(COST_TYPE));
annotationBuilder.set(LSP_SIG_TYPE, tunnel.annotations().value(LSP_SIG_TYPE));
annotationBuilder.set(PCE_INIT, tunnel.annotations().value(PCE_INIT));
annotationBuilder.set(DELEGATE, tunnel.annotations().value(DELEGATE));
annotationBuilder.set(PLSP_ID, String.valueOf(lspObj.getPlspId()));
annotationBuilder.set(PCC_TUNNEL_ID, String.valueOf(ipv4LspIdenTlv.getTunnelId()));
annotationBuilder.set(LOCAL_LSP_ID, tunnel.annotations().value(LOCAL_LSP_ID));
Tunnel updatedTunnel = new DefaultTunnel(tunnel.providerId(), tunnel.src(),
tunnel.dst(), tunnel.type(),
tunnel.state(), tunnel.groupId(),
tunnel.tunnelId(),
tunnel.tunnelName(),
tunnel.path(),
tunnel.resource(),
annotationBuilder.build());
return updatedTunnel;
}
@Override
public void closeConnectedClients() {
PcepClient pc;
......@@ -337,6 +550,294 @@ public class PcepClientControllerImpl implements PcepClientController {
return errMsg;
}
private boolean syncLabelDb(DeviceId deviceId) throws PcepParseException {
checkNotNull(deviceId);
DeviceId actualDevcieId = pceStore.getLsrIdDevice(deviceId.toString());
if (actualDevcieId == null) {
log.error("Device not available {}.", deviceId.toString());
pceStore.addPccLsr(deviceId);
return false;
}
PcepClient pc = connectedClients.get(PccId.pccId(IpAddress.valueOf(deviceId.toString())));
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.pushGlobalNodeLabel(pc, entry.getValue(),
IpAddress.valueOf(srcLsrId).getIp4Address().toInt(),
PcepLabelOp.ADD, false);
}
Map<Link, LabelResourceId> adjLabelMap = pceStore.getAdjLabels();
for (Entry<Link, LabelResourceId> entry : adjLabelMap.entrySet()) {
if (entry.getKey().src().deviceId().equals(actualDevcieId)) {
srTeHandler.pushAdjacencyLabel(pc,
entry.getValue(),
(int) entry.getKey().src().port().toLong(),
(int) entry.getKey().dst().port().toLong(),
PcepLabelOp.ADD
);
}
}
}
srTeHandler.pushGlobalNodeLabel(pc, LabelResourceId.labelResourceId(0),
0, PcepLabelOp.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;
}
/**
* 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());
// 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);
}
}
/**
* 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());
// 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());
}
}
}
@Override
public LabelStack computeLabelStack(Path path) {
return srTeHandler.computeLabelStack(path);
}
@Override
public boolean allocateLocalLabel(Tunnel tunnel) {
return crHandler.allocateLabel(tunnel);
}
/**
* Creates label stack for ERO object from network resource.
*
* @param labelStack
* @param path (hop list)
* @return list of ERO subobjects
*/
@Override
public LinkedList<PcepValueType> createPcepLabelStack(DefaultLabelStack labelStack, Path path) {
checkNotNull(labelStack);
LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>();
Iterator<Link> links = path.links().iterator();
LabelResourceId label = null;
Link link = null;
PcepValueType subObj = null;
PcepNai nai = null;
Device dstNode = null;
long srcPortNo, dstPortNo;
ListIterator<LabelResourceId> labelListIterator = labelStack.labelResources().listIterator();
while (labelListIterator.hasNext()) {
label = labelListIterator.next();
link = links.next();
srcPortNo = link.src().port().toLong();
srcPortNo = ((srcPortNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? srcPortNo & SET : srcPortNo;
dstPortNo = link.dst().port().toLong();
dstPortNo = ((dstPortNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? dstPortNo & SET : dstPortNo;
nai = new PcepNaiIpv4Adjacency((int) srcPortNo, (int) dstPortNo);
subObj = new SrEroSubObject(PcepNaiIpv4Adjacency.ST_TYPE, false, false, false, true, (int) label.labelId(),
nai);
llSubObjects.add(subObj);
dstNode = deviceService.getDevice(link.dst().deviceId());
nai = new PcepNaiIpv4NodeId(Ip4Address.valueOf(dstNode.annotations().value(LSRID)).toInt());
if (!labelListIterator.hasNext()) {
log.error("Malformed label stack.");
}
label = labelListIterator.next();
subObj = new SrEroSubObject(PcepNaiIpv4NodeId.ST_TYPE, false, false, false, true, (int) label.labelId(),
nai);
llSubObjects.add(subObj);
}
return llSubObjects;
}
/**
* Implementation of an Pcep Agent which is responsible for
* keeping track of connected clients and the state in which
......@@ -370,7 +871,6 @@ public class PcepClientControllerImpl implements PcepClientController {
+ "connected client: pccIp {}. Aborting ..", pccId.toString());
return false;
}
return true;
}
......@@ -479,7 +979,7 @@ public class PcepClientControllerImpl implements PcepClientController {
} else if (pathNameTlv != null) {
tunnel = preSyncLspDbByName.get(Arrays.toString(pathNameTlv.getValue()));
if (tunnel != null) {
preSyncLspDbByName.remove(tunnel.tunnelName());
preSyncLspDbByName.remove(tunnel.tunnelName().value());
}
}
......@@ -566,4 +1066,130 @@ public class PcepClientControllerImpl implements PcepClientController {
}
}
}
/*
* Handle device events.
*/
private class InternalDeviceListener implements DeviceListener {
@Override
public void event(DeviceEvent event) {
Device specificDevice = 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());
try {
syncLabelDb(pccDeviceId);
} catch (PcepParseException e) {
log.error("Exception caught in sending label masg to PCC while in sync.");
}
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 = 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;
}
}
}
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);
}
}
}
}
......
......@@ -111,13 +111,13 @@ public class PcepControllerImpl implements PcepController {
@Override
public Boolean deleteTunnel(String id) {
// TODO Auto-generated method stub
return null;
return false;
}
@Override
public Boolean updateTunnelBandwidth(String id, long bandwidth) {
// TODO Auto-generated method stub
return null;
return false;
}
@Override
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.pce.pcestore;
package org.onosproject.pcelabelstore;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
......@@ -24,7 +24,7 @@ import org.junit.Test;
import org.onosproject.incubator.net.resource.label.LabelResourceId;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
import org.onosproject.pcelabelstore.api.LspLocalLabelInfo;
/**
* Unit tests for DefaultLspLocalLabelInfo class.
......
/*
* 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.pcelabelstore;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
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.tunnel.TunnelId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultLink;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.PortNumber;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.pcelabelstore.api.LspLocalLabelInfo;
import org.onosproject.pcelabelstore.util.TestStorageService;
/**
* Unit tests for DistributedPceStore class.
*/
public class DistributedPceLabelStoreTest {
private DistributedPceLabelStore distrPceStore;
private DeviceId deviceId1 = DeviceId.deviceId("foo");
private DeviceId deviceId2 = DeviceId.deviceId("goo");
private DeviceId deviceId3 = DeviceId.deviceId("yaa");
private DeviceId deviceId4 = DeviceId.deviceId("zoo");
private LabelResourceId labelId1 = LabelResourceId.labelResourceId(1);
private LabelResourceId labelId2 = LabelResourceId.labelResourceId(2);
private LabelResourceId labelId3 = LabelResourceId.labelResourceId(3);
private LabelResourceId labelId4 = LabelResourceId.labelResourceId(4);
private PortNumber portNumber1 = PortNumber.portNumber(1);
private PortNumber portNumber2 = PortNumber.portNumber(2);
private PortNumber portNumber3 = PortNumber.portNumber(3);
private PortNumber portNumber4 = PortNumber.portNumber(4);
private ConnectPoint srcConnectionPoint1 = new ConnectPoint(deviceId1, portNumber1);
private ConnectPoint dstConnectionPoint2 = new ConnectPoint(deviceId2, portNumber2);
private ConnectPoint srcConnectionPoint3 = new ConnectPoint(deviceId3, portNumber3);
private ConnectPoint dstConnectionPoint4 = new ConnectPoint(deviceId4, portNumber4);
private LabelResource labelResource1 = new DefaultLabelResource(deviceId1, labelId1);
private LabelResource labelResource2 = new DefaultLabelResource(deviceId2, labelId2);
private LabelResource labelResource3 = new DefaultLabelResource(deviceId3, labelId3);
private LabelResource labelResource4 = new DefaultLabelResource(deviceId4, labelId4);
private Link link1;
private Link link2;
private List<LabelResource> labelList1 = new LinkedList<>();
private List<LabelResource> labelList2 = new LinkedList<>();
private TunnelId tunnelId1 = TunnelId.valueOf("1");
private TunnelId tunnelId2 = TunnelId.valueOf("2");
private TunnelId tunnelId3 = TunnelId.valueOf("3");
private TunnelId tunnelId4 = TunnelId.valueOf("4");
List<LspLocalLabelInfo> lspLocalLabelInfoList1 = new LinkedList<>();
List<LspLocalLabelInfo> lspLocalLabelInfoList2 = new LinkedList<>();
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@Before
public void setUp() throws Exception {
distrPceStore = new DistributedPceLabelStore();
// initialization
distrPceStore.storageService = new TestStorageService();
distrPceStore.activate();
// Initialization of member variables
link1 = DefaultLink.builder()
.providerId(new ProviderId("eth", "1"))
.annotations(DefaultAnnotations.builder().set("key1", "yahoo").build())
.src(srcConnectionPoint1)
.dst(dstConnectionPoint2)
.type(Link.Type.DIRECT)
.state(Link.State.ACTIVE)
.build();
link2 = DefaultLink.builder()
.providerId(new ProviderId("mac", "2"))
.annotations(DefaultAnnotations.builder().set("key2", "google").build())
.src(srcConnectionPoint3)
.dst(dstConnectionPoint4)
.type(Link.Type.DIRECT)
.state(Link.State.ACTIVE)
.build();
labelList1.add(labelResource1);
labelList1.add(labelResource2);
labelList2.add(labelResource3);
labelList2.add(labelResource4);
// Create pceccTunnelInfo1
DeviceId deviceId1 = DeviceId.deviceId("foo");
LabelResourceId inLabelId1 = LabelResourceId.labelResourceId(1);
LabelResourceId outLabelId1 = LabelResourceId.labelResourceId(2);
LspLocalLabelInfo lspLocalLabel1 = DefaultLspLocalLabelInfo.builder()
.deviceId(deviceId1)
.inLabelId(inLabelId1)
.outLabelId(outLabelId1)
.build();
lspLocalLabelInfoList1.add(lspLocalLabel1);
distrPceStore.addTunnelInfo(tunnelId1, lspLocalLabelInfoList1);
// Create pceccTunnelInfo2
DeviceId deviceId2 = DeviceId.deviceId("foo");
LabelResourceId inLabelId2 = LabelResourceId.labelResourceId(3);
LabelResourceId outLabelId2 = LabelResourceId.labelResourceId(4);
LspLocalLabelInfo lspLocalLabel2 = DefaultLspLocalLabelInfo.builder()
.deviceId(deviceId2)
.inLabelId(inLabelId2)
.outLabelId(outLabelId2)
.build();
lspLocalLabelInfoList2.add(lspLocalLabel2);
distrPceStore.addTunnelInfo(tunnelId2, lspLocalLabelInfoList2);
}
@After
public void tearDown() throws Exception {
}
/**
* Checks the operation of addGlobalNodeLabel() method.
*/
@Test
public void testAddGlobalNodeLabel() {
// add device with label
distrPceStore.addGlobalNodeLabel(deviceId1, labelId1);
assertThat(distrPceStore.existsGlobalNodeLabel(deviceId1), is(true));
assertThat(distrPceStore.getGlobalNodeLabel(deviceId1), is(labelId1));
distrPceStore.addGlobalNodeLabel(deviceId2, labelId2);
assertThat(distrPceStore.existsGlobalNodeLabel(deviceId2), is(true));
assertThat(distrPceStore.getGlobalNodeLabel(deviceId2), is(labelId2));
}
/**
* Checks the operation of addAdjLabel() method.
*/
@Test
public void testAddAdjLabel() {
// link with list of labels
distrPceStore.addAdjLabel(link1, labelId1);
assertThat(distrPceStore.existsAdjLabel(link1), is(true));
assertThat(distrPceStore.getAdjLabel(link1), is(labelId1));
distrPceStore.addAdjLabel(link2, labelId2);
assertThat(distrPceStore.existsAdjLabel(link2), is(true));
assertThat(distrPceStore.getAdjLabel(link2), is(labelId2));
}
/**
* Checks the operation of addTunnelInfo() method.
*/
@Test
public void testAddTunnelInfo() {
// TunnelId with device label store information
distrPceStore.addTunnelInfo(tunnelId1, lspLocalLabelInfoList1);
assertThat(distrPceStore.existsTunnelInfo(tunnelId1), is(true));
assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(lspLocalLabelInfoList1));
distrPceStore.addTunnelInfo(tunnelId2, lspLocalLabelInfoList2);
assertThat(distrPceStore.existsTunnelInfo(tunnelId2), is(true));
assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(lspLocalLabelInfoList2));
}
/**
* Checks the operation of existsGlobalNodeLabel() method.
*/
@Test
public void testExistsGlobalNodeLabel() {
testAddGlobalNodeLabel();
assertThat(distrPceStore.existsGlobalNodeLabel(deviceId1), is(true));
assertThat(distrPceStore.existsGlobalNodeLabel(deviceId2), is(true));
assertThat(distrPceStore.existsGlobalNodeLabel(deviceId3), is(false));
assertThat(distrPceStore.existsGlobalNodeLabel(deviceId4), is(false));
}
/**
* Checks the operation of existsAdjLabel() method.
*/
@Test
public void testExistsAdjLabel() {
testAddAdjLabel();
assertThat(distrPceStore.existsAdjLabel(link1), is(true));
assertThat(distrPceStore.existsAdjLabel(link2), is(true));
}
/**
* Checks the operation of existsTunnelInfo() method.
*/
@Test
public void testExistsTunnelInfo() {
testAddTunnelInfo();
assertThat(distrPceStore.existsTunnelInfo(tunnelId1), is(true));
assertThat(distrPceStore.existsTunnelInfo(tunnelId2), is(true));
assertThat(distrPceStore.existsTunnelInfo(tunnelId3), is(false));
assertThat(distrPceStore.existsTunnelInfo(tunnelId4), is(false));
}
/**
* Checks the operation of getGlobalNodeLabelCount() method.
*/
@Test
public void testGetGlobalNodeLabelCount() {
testAddGlobalNodeLabel();
assertThat(distrPceStore.getGlobalNodeLabelCount(), is(2));
}
/**
* Checks the operation of getAdjLabelCount() method.
*/
@Test
public void testGetAdjLabelCount() {
testAddAdjLabel();
assertThat(distrPceStore.getAdjLabelCount(), is(2));
}
/**
* Checks the operation of getTunnelInfoCount() method.
*/
@Test
public void testGetTunnelInfoCount() {
testAddTunnelInfo();
assertThat(distrPceStore.getTunnelInfoCount(), is(2));
}
/**
* Checks the operation of getGlobalNodeLabels() method.
*/
@Test
public void testGetGlobalNodeLabels() {
testAddGlobalNodeLabel();
Map<DeviceId, LabelResourceId> nodeLabelMap = distrPceStore.getGlobalNodeLabels();
assertThat(nodeLabelMap, is(notNullValue()));
assertThat(nodeLabelMap.isEmpty(), is(false));
assertThat(nodeLabelMap.size(), is(2));
}
/**
* Checks the operation of getAdjLabels() method.
*/
@Test
public void testGetAdjLabels() {
testAddAdjLabel();
Map<Link, LabelResourceId> adjLabelMap = distrPceStore.getAdjLabels();
assertThat(adjLabelMap, is(notNullValue()));
assertThat(adjLabelMap.isEmpty(), is(false));
assertThat(adjLabelMap.size(), is(2));
}
/**
* Checks the operation of getTunnelInfos() method.
*/
@Test
public void testGetTunnelInfos() {
testAddTunnelInfo();
Map<TunnelId, List<LspLocalLabelInfo>> tunnelInfoMap = distrPceStore.getTunnelInfos();
assertThat(tunnelInfoMap, is(notNullValue()));
assertThat(tunnelInfoMap.isEmpty(), is(false));
assertThat(tunnelInfoMap.size(), is(2));
}
/**
* Checks the operation of getGlobalNodeLabel() method.
*/
@Test
public void testGetGlobalNodeLabel() {
testAddGlobalNodeLabel();
// deviceId1 with labelId1
assertThat(deviceId1, is(notNullValue()));
assertThat(distrPceStore.getGlobalNodeLabel(deviceId1), is(labelId1));
// deviceId2 with labelId2
assertThat(deviceId2, is(notNullValue()));
assertThat(distrPceStore.getGlobalNodeLabel(deviceId2), is(labelId2));
}
/**
* Checks the operation of getAdjLabel() method.
*/
@Test
public void testGetAdjLabel() {
testAddAdjLabel();
// link1 with labels
assertThat(link1, is(notNullValue()));
assertThat(distrPceStore.getAdjLabel(link1), is(labelId1));
// link2 with labels
assertThat(link2, is(notNullValue()));
assertThat(distrPceStore.getAdjLabel(link2), is(labelId2));
}
/**
* Checks the operation of getTunnelInfo() method.
*/
@Test
public void testGetTunnelInfo() {
testAddTunnelInfo();
// tunnelId1 with device label store info
assertThat(tunnelId1, is(notNullValue()));
assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(lspLocalLabelInfoList1));
// tunnelId2 with device label store info
assertThat(tunnelId2, is(notNullValue()));
assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(lspLocalLabelInfoList2));
}
/**
* Checks the operation of removeGlobalNodeLabel() method.
*/
@Test
public void testRemoveGlobalNodeLabel() {
testAddGlobalNodeLabel();
assertThat(distrPceStore.removeGlobalNodeLabel(deviceId1), is(true));
assertThat(distrPceStore.removeGlobalNodeLabel(deviceId2), is(true));
}
/**
* Checks the operation of removeAdjLabel() method.
*/
@Test
public void testRemoveAdjLabel() {
testAddAdjLabel();
assertThat(distrPceStore.removeAdjLabel(link1), is(true));
assertThat(distrPceStore.removeAdjLabel(link2), is(true));
}
/**
* Checks the operation of removeTunnelInfo() method.
*/
@Test
public void testRemoveTunnelInfo() {
testAddTunnelInfo();
assertThat(distrPceStore.removeTunnelInfo(tunnelId1), is(true));
assertThat(distrPceStore.removeTunnelInfo(tunnelId2), is(true));
}
}
......@@ -13,14 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.pce.pceservice;
package org.onosproject.pcelabelstore.label;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.onosproject.net.Link.Type.DIRECT;
import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;
......@@ -29,8 +28,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.IpAddress;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.core.DefaultGroupId;
import org.onosproject.incubator.net.tunnel.Tunnel;
import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
......@@ -40,19 +37,24 @@ import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.incubator.net.tunnel.DefaultTunnel;
import org.onosproject.incubator.net.resource.label.LabelResourceId;
import org.onosproject.incubator.net.resource.label.LabelResourceService;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.Annotations;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultDevice;
import org.onosproject.net.DefaultPath;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flowobjective.FlowObjectiveService;
import org.onosproject.net.Path;
import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
import org.onosproject.pce.pcestore.api.PceStore;
import org.onosproject.pce.pcestore.PceccTunnelInfo;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.pce.util.LabelResourceAdapter;
import org.onosproject.pce.util.PceStoreAdapter;
import org.onosproject.pcelabelstore.api.LspLocalLabelInfo;
import org.onosproject.pcelabelstore.api.PceLabelStore;
import org.onosproject.pcelabelstore.util.LabelResourceAdapter;
import org.onosproject.pcelabelstore.util.MockDeviceService;
import org.onosproject.pcelabelstore.util.PceLabelStoreAdapter;
import org.onosproject.pcep.controller.impl.BasicPceccHandler;
import org.onosproject.pcep.controller.impl.PcepClientControllerImpl;
import org.onosproject.net.DefaultLink;
import org.onosproject.net.Link;
......@@ -63,13 +65,13 @@ public class BasicPceccHandlerTest {
public static final long LOCAL_LABEL_SPACE_MIN = 5122;
public static final long LOCAL_LABEL_SPACE_MAX = 9217;
private static final String L3 = "L3";
private static final String LSRID = "lsrId";
private BasicPceccHandler pceccHandler;
protected LabelResourceService labelRsrcService;
protected PceStore pceStore;
private FlowObjectiveService flowObjectiveService;
private CoreService coreService;
private ApplicationId appId;
protected MockDeviceService deviceService;
protected PceLabelStore pceStore;
private TunnelEndPoint src = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(23423));
private TunnelEndPoint dst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(32421));
private DefaultGroupId groupId = new DefaultGroupId(92034);
......@@ -78,7 +80,8 @@ public class BasicPceccHandlerTest {
private ProviderId producerName = new ProviderId("producer1", "13");
private Path path;
private Tunnel tunnel;
private PceccTunnelInfo pceccTunnelInfo;
List<LspLocalLabelInfo> lspLocalLabelInfoList;
private Device deviceD1, deviceD2, deviceD3, deviceD4, deviceD5;
private DeviceId deviceId1;
private DeviceId deviceId2;
private DeviceId deviceId3;
......@@ -94,13 +97,14 @@ public class BasicPceccHandlerTest {
public void setUp() throws Exception {
pceccHandler = BasicPceccHandler.getInstance();
labelRsrcService = new LabelResourceAdapter();
pceStore = new PceStoreAdapter();
flowObjectiveService = new PceManagerTest.MockFlowObjService();
coreService = new PceManagerTest.MockCoreService();
appId = coreService.registerApplication("org.onosproject.pce");
pceccHandler.initialize(labelRsrcService, flowObjectiveService, appId, pceStore);
pceStore = new PceLabelStoreAdapter();
deviceService = new MockDeviceService();
pceccHandler.initialize(labelRsrcService,
deviceService,
pceStore,
new PcepClientControllerImpl());
// Cretae tunnel test
// Create tunnel test
// Link
ProviderId providerId = new ProviderId("of", "foo");
deviceId1 = DeviceId.deviceId("of:A");
......@@ -115,6 +119,41 @@ public class BasicPceccHandlerTest {
port5 = PortNumber.portNumber(5);
List<Link> linkList = new LinkedList<>();
// Making L3 devices
DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder();
builderDev1.set(AnnotationKeys.TYPE, L3);
builderDev1.set(LSRID, "1.1.1.1");
deviceD1 = new MockDevice(deviceId1, builderDev1.build());
deviceService.addDevice(deviceD1);
// Making L3 devices
DefaultAnnotations.Builder builderDev2 = DefaultAnnotations.builder();
builderDev2.set(AnnotationKeys.TYPE, L3);
builderDev2.set(LSRID, "2.2.2.2");
deviceD2 = new MockDevice(deviceId2, builderDev2.build());
deviceService.addDevice(deviceD2);
// Making L3 devices
DefaultAnnotations.Builder builderDev3 = DefaultAnnotations.builder();
builderDev3.set(AnnotationKeys.TYPE, L3);
builderDev3.set(LSRID, "3.3.3.3");
deviceD3 = new MockDevice(deviceId3, builderDev3.build());
deviceService.addDevice(deviceD3);
// Making L3 devices
DefaultAnnotations.Builder builderDev4 = DefaultAnnotations.builder();
builderDev4.set(AnnotationKeys.TYPE, L3);
builderDev4.set(LSRID, "4.4.4.4");
deviceD4 = new MockDevice(deviceId4, builderDev4.build());
deviceService.addDevice(deviceD4);
// Making L3 devices
DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder();
builderDev5.set(AnnotationKeys.TYPE, L3);
builderDev5.set(LSRID, "5.5.5.5");
deviceD5 = new MockDevice(deviceId5, builderDev5.build());
deviceService.addDevice(deviceD5);
Link l1 = DefaultLink.builder()
.providerId(providerId)
.annotations(DefaultAnnotations.builder().set("key1", "yahoo").build())
......@@ -163,7 +202,6 @@ public class BasicPceccHandlerTest {
@After
public void tearDown() throws Exception {
PceManagerTest.flowsDownloaded = 0;
}
/**
......@@ -179,7 +217,6 @@ public class BasicPceccHandlerTest {
*/
@Test
public void testAllocateLabel() {
List<LspLocalLabelInfo> lspLocalLabelInfoList;
Iterator<LspLocalLabelInfo> iterator;
LspLocalLabelInfo lspLocalLabelInfo;
DeviceId deviceId;
......@@ -192,8 +229,7 @@ public class BasicPceccHandlerTest {
assertThat(pceccHandler.allocateLabel(tunnel), is(true));
// Check list of devices with IN and OUT labels whether stored properly in store
pceccTunnelInfo = pceStore.getTunnelInfo(tunnel.tunnelId());
lspLocalLabelInfoList = pceccTunnelInfo.lspLocalLabelInfoList();
lspLocalLabelInfoList = pceStore.getTunnelInfo(tunnel.tunnelId());
iterator = lspLocalLabelInfoList.iterator();
// Retrieve values and check device5
......@@ -281,7 +317,13 @@ public class BasicPceccHandlerTest {
pceccHandler.releaseLabel(tunnel);
// Retrieve from store. Store should not contain this tunnel info.
pceccTunnelInfo = pceStore.getTunnelInfo(tunnel.tunnelId());
assertThat(pceccTunnelInfo, is(nullValue()));
lspLocalLabelInfoList = pceStore.getTunnelInfo(tunnel.tunnelId());
assertThat(lspLocalLabelInfoList, is(nullValue()));
}
private class MockDevice extends DefaultDevice {
MockDevice(DeviceId id, Annotations annotations) {
super(null, id, null, null, null, null, null, null, annotations);
}
}
}
......
......@@ -13,19 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.pce.pceservice;
package org.onosproject.pcelabelstore.label;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.onosproject.net.Link.Type.DIRECT;
import static org.onosproject.pce.pceservice.PathComputationTest.D1;
import static org.onosproject.pce.pceservice.PathComputationTest.D2;
import static org.onosproject.pce.pceservice.PathComputationTest.D3;
import static org.onosproject.pce.pceservice.PathComputationTest.D4;
import static org.onosproject.pce.pceservice.PathComputationTest.D5;
import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;
......@@ -33,9 +27,8 @@ import java.util.LinkedList;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.IpAddress;
import org.onosproject.incubator.net.resource.label.LabelResourceId;
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.LabelResourceService;
import org.onosproject.incubator.net.tunnel.LabelStack;
......@@ -48,15 +41,19 @@ import org.onosproject.net.DefaultPath;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flowobjective.FlowObjectiveService;
import org.onosproject.net.Path;
import org.onosproject.pce.pceservice.PathComputationTest.MockNetConfigRegistryAdapter;
import org.onosproject.pce.pcestore.api.PceStore;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.pce.util.LabelResourceAdapter;
import org.onosproject.pce.util.PceStoreAdapter;
import org.onosproject.pce.util.MockDeviceService;
import org.onosproject.pcelabelstore.api.PceLabelStore;
import org.onosproject.pcelabelstore.util.LabelResourceAdapter;
import org.onosproject.pcelabelstore.util.MockDeviceService;
import org.onosproject.pcelabelstore.util.MockNetConfigRegistryAdapter;
import org.onosproject.pcelabelstore.util.MockPcepClientController;
import org.onosproject.pcelabelstore.util.PceLabelStoreAdapter;
import org.onosproject.pcelabelstore.util.PcepClientAdapter;
import org.onosproject.pcep.api.DeviceCapability;
import org.onosproject.pcep.controller.PccId;
import org.onosproject.pcep.controller.impl.PceccSrTeBeHandler;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.onosproject.net.DefaultLink;
import org.onosproject.net.Link;
......@@ -71,15 +68,14 @@ public class PceccSrTeBeHandlerTest {
private static final String LSRID = "lsrId";
private PceccSrTeBeHandler srTeHandler;
private CoreService coreService;
private LabelResourceAdminService labelRsrcAdminService;
private LabelResourceService labelRsrcService;
private PceStore pceStore;
private PceLabelStore pceStore;
private MockDeviceService deviceService;
private FlowObjectiveService flowObjectiveService;
private MockNetConfigRegistryAdapter netCfgService = new PathComputationTest.MockNetConfigRegistryAdapter();
private ApplicationId appId;
private MockNetConfigRegistryAdapter netCfgService = new MockNetConfigRegistryAdapter();
private MockPcepClientController clientController = new MockPcepClientController();
private ProviderId providerId;
private DeviceId deviceId1, deviceId2, deviceId3, deviceId4, deviceId5;
private Device deviceD1;
private Device deviceD2;
private Device deviceD3;
......@@ -103,18 +99,52 @@ public class PceccSrTeBeHandlerTest {
srTeHandler = PceccSrTeBeHandler.getInstance();
labelRsrcService = new LabelResourceAdapter();
labelRsrcAdminService = new LabelResourceAdapter();
flowObjectiveService = new PceManagerTest.MockFlowObjService();
coreService = new PceManagerTest.MockCoreService();
appId = coreService.registerApplication("org.onosproject.pce");
pceStore = new PceStoreAdapter();
pceStore = new PceLabelStoreAdapter();
deviceService = new MockDeviceService();
srTeHandler.initialize(labelRsrcAdminService, labelRsrcService, flowObjectiveService, appId, pceStore,
srTeHandler.initialize(labelRsrcAdminService,
labelRsrcService,
clientController,
pceStore,
deviceService);
// Creates path
// Creates list of links
providerId = new ProviderId("of", "foo");
PccId pccId1 = PccId.pccId(IpAddress.valueOf("11.1.1.1"));
PccId pccId2 = PccId.pccId(IpAddress.valueOf("12.1.1.1"));
PccId pccId3 = PccId.pccId(IpAddress.valueOf("13.1.1.1"));
PccId pccId4 = PccId.pccId(IpAddress.valueOf("14.1.1.1"));
PccId pccId5 = PccId.pccId(IpAddress.valueOf("15.1.1.1"));
PcepClientAdapter pc1 = new PcepClientAdapter();
pc1.init(pccId1, PcepVersion.PCEP_1);
PcepClientAdapter pc2 = new PcepClientAdapter();
pc2.init(pccId2, PcepVersion.PCEP_1);
PcepClientAdapter pc3 = new PcepClientAdapter();
pc3.init(pccId3, PcepVersion.PCEP_1);
PcepClientAdapter pc4 = new PcepClientAdapter();
pc4.init(pccId4, PcepVersion.PCEP_1);
PcepClientAdapter pc5 = new PcepClientAdapter();
pc5.init(pccId5, PcepVersion.PCEP_1);
clientController.addClient(pccId1, pc1);
clientController.addClient(pccId2, pc2);
clientController.addClient(pccId3, pc3);
clientController.addClient(pccId4, pc4);
clientController.addClient(pccId5, pc5);
deviceId1 = DeviceId.deviceId("11.1.1.1");
deviceId2 = DeviceId.deviceId("12.1.1.1");
deviceId3 = DeviceId.deviceId("13.1.1.1");
deviceId4 = DeviceId.deviceId("14.1.1.1");
deviceId5 = DeviceId.deviceId("15.1.1.1");
// Devices
DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder();
DefaultAnnotations.Builder builderDev2 = DefaultAnnotations.builder();
......@@ -123,25 +153,25 @@ public class PceccSrTeBeHandlerTest {
DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder();
builderDev1.set(AnnotationKeys.TYPE, L3);
builderDev1.set(LSRID, "1.1.1.1");
builderDev1.set(LSRID, "11.1.1.1");
builderDev2.set(AnnotationKeys.TYPE, L3);
builderDev2.set(LSRID, "2.2.2.2");
builderDev2.set(LSRID, "12.1.1.1");
builderDev3.set(AnnotationKeys.TYPE, L3);
builderDev3.set(LSRID, "3.3.3.3");
builderDev3.set(LSRID, "13.1.1.1");
builderDev4.set(AnnotationKeys.TYPE, L3);
builderDev4.set(LSRID, "4.4.4.4");
builderDev4.set(LSRID, "14.1.1.1");
builderDev5.set(AnnotationKeys.TYPE, L3);
builderDev5.set(LSRID, "5.5.5.5");
builderDev5.set(LSRID, "15.1.1.1");
deviceD1 = new MockDevice(D1.deviceId(), builderDev1.build());
deviceD2 = new MockDevice(D2.deviceId(), builderDev2.build());
deviceD3 = new MockDevice(D3.deviceId(), builderDev3.build());
deviceD4 = new MockDevice(D4.deviceId(), builderDev4.build());
deviceD5 = new MockDevice(D5.deviceId(), builderDev5.build());
deviceD1 = new MockDevice(deviceId1, builderDev1.build());
deviceD2 = new MockDevice(deviceId2, builderDev2.build());
deviceD3 = new MockDevice(deviceId3, builderDev3.build());
deviceD4 = new MockDevice(deviceId4, builderDev4.build());
deviceD5 = new MockDevice(deviceId5, builderDev5.build());
deviceService.addDevice(deviceD1);
deviceService.addDevice(deviceD2);
......@@ -149,19 +179,19 @@ public class PceccSrTeBeHandlerTest {
deviceService.addDevice(deviceD4);
deviceService.addDevice(deviceD5);
DeviceCapability device1Cap = netCfgService.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class);
DeviceCapability device1Cap = netCfgService.addConfig(deviceId1, DeviceCapability.class);
device1Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
DeviceCapability device2Cap = netCfgService.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class);
DeviceCapability device2Cap = netCfgService.addConfig(deviceId2, DeviceCapability.class);
device2Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
DeviceCapability device3Cap = netCfgService.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class);
DeviceCapability device3Cap = netCfgService.addConfig(deviceId3, DeviceCapability.class);
device3Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
DeviceCapability device4Cap = netCfgService.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class);
DeviceCapability device4Cap = netCfgService.addConfig(deviceId4, DeviceCapability.class);
device4Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
DeviceCapability device5Cap = netCfgService.addConfig(DeviceId.deviceId("5.5.5.5"), DeviceCapability.class);
DeviceCapability device5Cap = netCfgService.addConfig(deviceId5, DeviceCapability.class);
device5Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
// Port Numbers
......@@ -199,7 +229,6 @@ public class PceccSrTeBeHandlerTest {
@After
public void tearDown() throws Exception {
PceManagerTest.flowsDownloaded = 0;
}
/**
......@@ -228,45 +257,45 @@ public class PceccSrTeBeHandlerTest {
//device 1
String lsrId1 = "11.1.1.1";
// Allocate node label for specific device D1deviceId
assertThat(srTeHandler.allocateNodeLabel(D1.deviceId(), lsrId1), is(true));
assertThat(srTeHandler.allocateNodeLabel(deviceId1, lsrId1), is(true));
// Retrieve label from store
LabelResourceId labelId = pceStore.getGlobalNodeLabel(D1.deviceId());
LabelResourceId labelId = pceStore.getGlobalNodeLabel(deviceId1);
// Check whether label is generated for this device D1.deviceId()
assertThat(labelId, is(notNullValue()));
// device 2
String lsrId2 = "12.1.1.1";
// Allocate node label for specific device D2.deviceId()
assertThat(srTeHandler.allocateNodeLabel(D2.deviceId(), lsrId2), is(true));
assertThat(srTeHandler.allocateNodeLabel(deviceId2, lsrId2), is(true));
// Retrieve label from store
labelId = pceStore.getGlobalNodeLabel(D2.deviceId());
labelId = pceStore.getGlobalNodeLabel(deviceId2);
// Check whether label is generated for this device D2.deviceId()
assertThat(labelId, is(notNullValue()));
// device 3
String lsrId3 = "13.1.1.1";
// Allocate node label for specific device D3.deviceId()
assertThat(srTeHandler.allocateNodeLabel(D3.deviceId(), lsrId3), is(true));
assertThat(srTeHandler.allocateNodeLabel(deviceId3, lsrId3), is(true));
// Retrieve label from store
labelId = pceStore.getGlobalNodeLabel(D3.deviceId());
labelId = pceStore.getGlobalNodeLabel(deviceId3);
// Check whether label is generated for this device D3.deviceId()
assertThat(labelId, is(notNullValue()));
// device 4
String lsrId4 = "14.1.1.1";
// Allocate node label for specific device D4.deviceId()
assertThat(srTeHandler.allocateNodeLabel(D4.deviceId(), lsrId4), is(true));
assertThat(srTeHandler.allocateNodeLabel(deviceId4, lsrId4), is(true));
// Retrieve label from store
labelId = pceStore.getGlobalNodeLabel(D4.deviceId());
labelId = pceStore.getGlobalNodeLabel(deviceId4);
// Check whether label is generated for this device D4.deviceId()
assertThat(labelId, is(notNullValue()));
// device 5
String lsrId5 = "15.1.1.1";
// Allocate node label for specific device D5.deviceId()
assertThat(srTeHandler.allocateNodeLabel(D5.deviceId(), lsrId5), is(true));
assertThat(srTeHandler.allocateNodeLabel(deviceId5, lsrId5), is(true));
// Retrieve label from store
labelId = pceStore.getGlobalNodeLabel(D5.deviceId());
labelId = pceStore.getGlobalNodeLabel(deviceId5);
// Check whether label is generated for this device D5.deviceId()
assertThat(labelId, is(notNullValue()));
}
......@@ -282,41 +311,41 @@ public class PceccSrTeBeHandlerTest {
//device 1
String lsrId1 = "11.1.1.1";
// Check whether successfully released node label
assertThat(srTeHandler.releaseNodeLabel(D1.deviceId(), lsrId1), is(true));
assertThat(srTeHandler.releaseNodeLabel(deviceId1, lsrId1), is(true));
// Check whether successfully removed label from store
LabelResourceId labelId = pceStore.getGlobalNodeLabel(D1.deviceId());
LabelResourceId labelId = pceStore.getGlobalNodeLabel(deviceId1);
assertThat(labelId, is(nullValue()));
//device 2
String lsrId2 = "12.1.1.1";
// Check whether successfully released node label
assertThat(srTeHandler.releaseNodeLabel(D2.deviceId(), lsrId2), is(true));
assertThat(srTeHandler.releaseNodeLabel(deviceId2, lsrId2), is(true));
// Check whether successfully removed label from store
labelId = pceStore.getGlobalNodeLabel(D2.deviceId());
labelId = pceStore.getGlobalNodeLabel(deviceId2);
assertThat(labelId, is(nullValue()));
//device 3
String lsrId3 = "13.1.1.1";
// Check whether successfully released node label
assertThat(srTeHandler.releaseNodeLabel(D3.deviceId(), lsrId3), is(true));
assertThat(srTeHandler.releaseNodeLabel(deviceId3, lsrId3), is(true));
// Check whether successfully removed label from store
labelId = pceStore.getGlobalNodeLabel(D3.deviceId());
labelId = pceStore.getGlobalNodeLabel(deviceId3);
assertThat(labelId, is(nullValue()));
//device 4
String lsrId4 = "14.1.1.1";
// Check whether successfully released node label
assertThat(srTeHandler.releaseNodeLabel(D4.deviceId(), lsrId4), is(true));
assertThat(srTeHandler.releaseNodeLabel(deviceId4, lsrId4), is(true));
// Check whether successfully removed label from store
labelId = pceStore.getGlobalNodeLabel(D4.deviceId());
labelId = pceStore.getGlobalNodeLabel(deviceId4);
assertThat(labelId, is(nullValue()));
//device 5
String lsrId5 = "15.1.1.1";
// Check whether successfully released node label
assertThat(srTeHandler.releaseNodeLabel(D5.deviceId(), lsrId5), is(true));
assertThat(srTeHandler.releaseNodeLabel(deviceId5, lsrId5), is(true));
// Check whether successfully removed label from store
labelId = pceStore.getGlobalNodeLabel(D5.deviceId());
labelId = pceStore.getGlobalNodeLabel(deviceId5);
assertThat(labelId, is(nullValue()));
}
......@@ -394,15 +423,15 @@ public class PceccSrTeBeHandlerTest {
public void testComputeLabelStack() {
// Allocate node labels to each devices
labelId = LabelResourceId.labelResourceId(4097);
pceStore.addGlobalNodeLabel(D1.deviceId(), labelId);
pceStore.addGlobalNodeLabel(deviceId1, labelId);
labelId = LabelResourceId.labelResourceId(4098);
pceStore.addGlobalNodeLabel(D2.deviceId(), labelId);
pceStore.addGlobalNodeLabel(deviceId2, labelId);
labelId = LabelResourceId.labelResourceId(4099);
pceStore.addGlobalNodeLabel(D3.deviceId(), labelId);
pceStore.addGlobalNodeLabel(deviceId3, labelId);
labelId = LabelResourceId.labelResourceId(4100);
pceStore.addGlobalNodeLabel(D4.deviceId(), labelId);
pceStore.addGlobalNodeLabel(deviceId4, labelId);
labelId = LabelResourceId.labelResourceId(4101);
pceStore.addGlobalNodeLabel(D5.deviceId(), labelId);
pceStore.addGlobalNodeLabel(deviceId5, labelId);
// Allocate adjacency labels to each devices
labelId = LabelResourceId.labelResourceId(5122);
......
/*
* Copyright 2015-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.pcelabelstore.util;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import org.onosproject.store.service.ConsistentMap;
import org.onosproject.store.service.DistributedPrimitive;
import org.onosproject.store.service.MapEventListener;
import org.onosproject.store.service.Versioned;
/**
* Testing adapter for the consistent map.
*/
public class ConsistentMapAdapter<K, V> implements ConsistentMap<K, V> {
@Override
public String name() {
return null;
}
@Override
public DistributedPrimitive.Type primitiveType() {
return DistributedPrimitive.Type.CONSISTENT_MAP;
}
@Override
public int size() {
return 0;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public boolean containsKey(K key) {
return false;
}
@Override
public boolean containsValue(V value) {
return false;
}
@Override
public Versioned<V> get(K key) {
return null;
}
@Override
public Versioned<V> computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
return null;
}
@Override
public Versioned<V> compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
return null;
}
@Override
public Versioned<V> computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
return null;
}
@Override
public Versioned<V> computeIf(K key, Predicate<? super V> condition,
BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
return null;
}
@Override
public Versioned<V> put(K key, V value) {
return null;
}
@Override
public Versioned<V> putAndGet(K key, V value) {
return null;
}
@Override
public Versioned<V> remove(K key) {
return null;
}
@Override
public void clear() {
}
@Override
public Set<K> keySet() {
return null;
}
@Override
public Collection<Versioned<V>> values() {
return null;
}
@Override
public Set<Map.Entry<K, Versioned<V>>> entrySet() {
return null;
}
@Override
public Versioned<V> putIfAbsent(K key, V value) {
return null;
}
@Override
public boolean remove(K key, V value) {
return false;
}
@Override
public boolean remove(K key, long version) {
return false;
}
@Override
public Versioned replace(K key, V value) {
return null;
}
@Override
public boolean replace(K key, V oldValue, V newValue) {
return false;
}
@Override
public boolean replace(K key, long oldVersion, V newValue) {
return false;
}
@Override
public void addListener(MapEventListener<K, V> listener, Executor executor) {
}
@Override
public void removeListener(MapEventListener<K, V> listener) {
}
@Override
public Map<K, V> asJavaMap() {
return null;
}
}
/*
* 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.pcelabelstore.util;
import java.util.Collection;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import org.onosproject.store.service.AsyncDistributedSet;
import org.onosproject.store.service.SetEventListener;
/**
* Testing adapter for the distributed set.
*/
public class DistributedSetAdapter<E> implements AsyncDistributedSet<E> {
@Override
public CompletableFuture<Void> addListener(SetEventListener<E> listener) {
return null;
}
@Override
public CompletableFuture<Void> removeListener(SetEventListener<E> listener) {
return null;
}
@Override
public CompletableFuture<Boolean> add(E element) {
return null;
}
@Override
public CompletableFuture<Boolean> remove(E element) {
return null;
}
@Override
public CompletableFuture<Integer> size() {
return null;
}
@Override
public CompletableFuture<Boolean> isEmpty() {
return null;
}
@Override
public CompletableFuture<Void> clear() {
return null;
}
@Override
public CompletableFuture<Boolean> contains(E element) {
return null;
}
@Override
public CompletableFuture<Boolean> addAll(Collection<? extends E> c) {
return null;
}
@Override
public CompletableFuture<Boolean> containsAll(Collection<? extends E> c) {
return null;
}
@Override
public CompletableFuture<Boolean> retainAll(Collection<? extends E> c) {
return null;
}
@Override
public CompletableFuture<Boolean> removeAll(Collection<? extends E> c) {
return null;
}
@Override
public CompletableFuture<? extends Set<E>> getAsImmutableSet() {
return null;
}
@Override
public String name() {
return null;
}
}
/*
* Copyright 2015-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.pcelabelstore.util;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiFunction;
import org.onosproject.store.service.EventuallyConsistentMap;
import org.onosproject.store.service.EventuallyConsistentMapListener;
/**
* Testing adapter for EventuallyConsistentMap.
*/
public class EventuallyConsistentMapAdapter<K, V> implements EventuallyConsistentMap<K, V> {
@Override
public String name() {
return null;
}
@Override
public Type primitiveType() {
return Type.EVENTUALLY_CONSISTENT_MAP;
}
@Override
public int size() {
return 0;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public boolean containsKey(K key) {
return false;
}
@Override
public boolean containsValue(V value) {
return false;
}
@Override
public V get(K key) {
return null;
}
@Override
public void put(K key, V value) {
}
@Override
public V remove(K key) {
return null;
}
@Override
public void remove(K key, V value) {
}
@Override
public V compute(K key, BiFunction<K, V, V> recomputeFunction) {
return null;
}
@Override
public void putAll(Map<? extends K, ? extends V> m) {
}
@Override
public void clear() {
}
@Override
public Set<K> keySet() {
return null;
}
@Override
public Collection<V> values() {
return null;
}
@Override
public Set<Map.Entry<K, V>> entrySet() {
return null;
}
@Override
public void addListener(EventuallyConsistentMapListener<K, V> listener) {
}
@Override
public void removeListener(EventuallyConsistentMapListener<K, V> listener) {
}
@Override
public CompletableFuture<Void> destroy() {
return CompletableFuture.completedFuture(null);
}
}
/*
* 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.pcelabelstore.util;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Collection;
import java.util.LinkedList;
import java.util.Random;
import java.util.Set;
import org.onosproject.incubator.net.resource.label.DefaultLabelResource;
import org.onosproject.incubator.net.resource.label.LabelResource;
import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
import org.onosproject.incubator.net.resource.label.LabelResourceDelegate;
import org.onosproject.incubator.net.resource.label.LabelResourceEvent;
import org.onosproject.incubator.net.resource.label.LabelResourceId;
import org.onosproject.incubator.net.resource.label.LabelResourceListener;
import org.onosproject.incubator.net.resource.label.LabelResourcePool;
import org.onosproject.incubator.net.resource.label.LabelResourceProvider;
import org.onosproject.incubator.net.resource.label.LabelResourceProviderRegistry;
import org.onosproject.incubator.net.resource.label.LabelResourceProviderService;
import org.onosproject.incubator.net.resource.label.LabelResourceService;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceEvent;
import org.onosproject.net.device.DeviceEvent.Type;
import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.provider.AbstractListenerProviderRegistry;
import org.onosproject.net.provider.AbstractProviderService;
import com.google.common.collect.Multimap;
/**
* Provides test implementation of class LabelResourceService.
*/
public class LabelResourceAdapter
extends AbstractListenerProviderRegistry<LabelResourceEvent, LabelResourceListener,
LabelResourceProvider, LabelResourceProviderService>
implements LabelResourceService, LabelResourceAdminService, LabelResourceProviderRegistry {
public static final long GLOBAL_LABEL_SPACE_MIN = 4097;
public static final long GLOBAL_LABEL_SPACE_MAX = 5121;
public static final long LOCAL_LABEL_SPACE_MIN = 5122;
public static final long LOCAL_LABEL_SPACE_MAX = 9217;
private Random random = new Random();
@Override
public boolean createDevicePool(DeviceId deviceId,
LabelResourceId beginLabel,
LabelResourceId endLabel) {
return true;
}
@Override
public boolean createGlobalPool(LabelResourceId beginLabel,
LabelResourceId endLabel) {
return true;
}
@Override
public boolean destroyDevicePool(DeviceId deviceId) {
return true;
}
@Override
public boolean destroyGlobalPool() {
return true;
}
public long getLabelId(long min, long max) {
return random.nextInt((int) max - (int) min + 1) + (int) min;
}
@Override
public Collection<LabelResource> applyFromDevicePool(DeviceId deviceId,
long applyNum) {
Collection<LabelResource> labelList = new LinkedList<>();
LabelResource label = new DefaultLabelResource(deviceId,
LabelResourceId.labelResourceId(
getLabelId(LOCAL_LABEL_SPACE_MIN, LOCAL_LABEL_SPACE_MAX)));
labelList.add(label);
return labelList;
}
@Override
public Collection<LabelResource> applyFromGlobalPool(long applyNum) {
Collection<LabelResource> labelList = new LinkedList<>();
LabelResource label = new DefaultLabelResource(DeviceId.deviceId("foo"),
LabelResourceId.labelResourceId(
getLabelId(GLOBAL_LABEL_SPACE_MIN, GLOBAL_LABEL_SPACE_MAX)));
labelList.add(label);
return labelList;
}
@Override
public boolean releaseToDevicePool(Multimap<DeviceId, LabelResource> release) {
return true;
}
@Override
public boolean releaseToGlobalPool(Set<LabelResourceId> release) {
return true;
}
@Override
public boolean isDevicePoolFull(DeviceId deviceId) {
return false;
}
@Override
public boolean isGlobalPoolFull() {
return false;
}
@Override
public long getFreeNumOfDevicePool(DeviceId deviceId) {
return 4;
}
@Override
public long getFreeNumOfGlobalPool() {
return 4;
}
@Override
public LabelResourcePool getDeviceLabelResourcePool(DeviceId deviceId) {
return null;
}
@Override
public LabelResourcePool getGlobalLabelResourcePool() {
return null;
}
private class InternalLabelResourceDelegate implements LabelResourceDelegate {
@Override
public void notify(LabelResourceEvent event) {
post(event);
}
}
private class InternalDeviceListener implements DeviceListener {
@Override
public void event(DeviceEvent event) {
Device device = event.subject();
if (Type.DEVICE_REMOVED.equals(event.type())) {
destroyDevicePool(device.id());
}
}
}
private class InternalLabelResourceProviderService
extends AbstractProviderService<LabelResourceProvider>
implements LabelResourceProviderService {
protected InternalLabelResourceProviderService(LabelResourceProvider provider) {
super(provider);
}
@Override
public void deviceLabelResourcePoolDetected(DeviceId deviceId,
LabelResourceId beginLabel,
LabelResourceId endLabel) {
checkNotNull(deviceId, "deviceId is not null");
checkNotNull(beginLabel, "beginLabel is not null");
checkNotNull(endLabel, "endLabel is not null");
createDevicePool(deviceId, beginLabel, endLabel);
}
@Override
public void deviceLabelResourcePoolDestroyed(DeviceId deviceId) {
checkNotNull(deviceId, "deviceId is not null");
destroyDevicePool(deviceId);
}
}
@Override
protected LabelResourceProviderService createProviderService(LabelResourceProvider provider) {
return null;
}
}
/*
* 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.pcelabelstore.util;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.device.PortStatistics;
import org.onosproject.net.Device;
import org.onosproject.net.Device.Type;
import org.onosproject.net.DeviceId;
import org.onosproject.net.MastershipRole;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.device.DeviceService;
/**
* Test fixture for the device service.
*/
public class MockDeviceService implements DeviceService {
private List<Device> devices = new LinkedList<>();
private DeviceListener listener;
/**
* Adds a new device.
*
* @param dev device to be added
*/
public void addDevice(Device dev) {
devices.add(dev);
}
/**
* Removes the specified device.
*
* @param dev device to be removed
*/
public void removeDevice(Device dev) {
devices.remove(dev);
}
@Override
public Device getDevice(DeviceId deviceId) {
for (Device dev : devices) {
if (dev.id().equals(deviceId)) {
return dev;
}
}
return null;
}
@Override
public Iterable<Device> getAvailableDevices() {
return devices;
}
@Override
public void addListener(DeviceListener listener) {
this.listener = listener;
}
/**
* Get the listener.
*/
public DeviceListener getListener() {
return listener;
}
@Override
public void removeListener(DeviceListener listener) {
// TODO Auto-generated method stub
}
@Override
public int getDeviceCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Iterable<Device> getDevices() {
// TODO Auto-generated method stub
return null;
}
@Override
public Iterable<Device> getDevices(Type type) {
// TODO Auto-generated method stub
return null;
}
@Override
public Iterable<Device> getAvailableDevices(Type type) {
// TODO Auto-generated method stub
return null;
}
@Override
public MastershipRole getRole(DeviceId deviceId) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<Port> getPorts(DeviceId deviceId) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<PortStatistics> getPortStatistics(DeviceId deviceId) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<PortStatistics> getPortDeltaStatistics(DeviceId deviceId) {
// TODO Auto-generated method stub
return null;
}
@Override
public Port getPort(DeviceId deviceId, PortNumber portNumber) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isAvailable(DeviceId deviceId) {
// TODO Auto-generated method stub
return false;
}
}
package org.onosproject.pcelabelstore.util;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.onosproject.net.DeviceId;
import org.onosproject.net.config.Config;
import org.onosproject.net.config.ConfigApplyDelegate;
import org.onosproject.net.config.ConfigFactory;
import org.onosproject.net.config.NetworkConfigListener;
import org.onosproject.net.config.NetworkConfigRegistry;
import org.onosproject.net.config.NetworkConfigService;
import org.onosproject.net.config.SubjectFactory;
import org.onosproject.pcep.api.DeviceCapability;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
/* Mock test for network config registry. */
public class MockNetConfigRegistryAdapter implements NetworkConfigService, NetworkConfigRegistry {
private ConfigFactory cfgFactory;
private Map<DeviceId, DeviceCapability> classConfig = new HashMap<>();
@Override
public void registerConfigFactory(ConfigFactory configFactory) {
cfgFactory = configFactory;
}
@Override
public void unregisterConfigFactory(ConfigFactory configFactory) {
cfgFactory = null;
}
@Override
public <S, C extends Config<S>> C addConfig(S subject, Class<C> configClass) {
if (configClass == DeviceCapability.class) {
DeviceCapability devCap = new DeviceCapability();
classConfig.put((DeviceId) subject, devCap);
JsonNode node = new ObjectNode(new MockJsonNode());
ObjectMapper mapper = new ObjectMapper();
ConfigApplyDelegate delegate = new InternalApplyDelegate();
devCap.init((DeviceId) subject, null, node, mapper, delegate);
return (C) devCap;
}
return null;
}
@Override
public <S, C extends Config<S>> void removeConfig(S subject, Class<C> configClass) {
classConfig.remove(subject);
}
@Override
public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) {
if (configClass == DeviceCapability.class) {
return (C) classConfig.get(subject);
}
return null;
}
private class MockJsonNode extends JsonNodeFactory {
}
// Auxiliary delegate to receive notifications about changes applied to
// the network configuration - by the apps.
private class InternalApplyDelegate implements ConfigApplyDelegate {
@Override
public void onApply(Config config) {
//configs.put(config.subject(), config.node());
}
}
@Override
public void addListener(NetworkConfigListener listener) {
// TODO Auto-generated method stub
}
@Override
public void removeListener(NetworkConfigListener listener) {
// TODO Auto-generated method stub
}
@Override
public Set<ConfigFactory> getConfigFactories() {
// TODO Auto-generated method stub
return null;
}
@Override
public <S, C extends Config<S>> Set<ConfigFactory<S, C>> getConfigFactories(Class<S> subjectClass) {
// TODO Auto-generated method stub
return null;
}
@Override
public <S, C extends Config<S>> ConfigFactory<S, C> getConfigFactory(Class<C> configClass) {
// TODO Auto-generated method stub
return null;
}
@Override
public Set<Class> getSubjectClasses() {
// TODO Auto-generated method stub
return null;
}
@Override
public SubjectFactory getSubjectFactory(String subjectClassKey) {
// TODO Auto-generated method stub
return null;
}
@Override
public SubjectFactory getSubjectFactory(Class subjectClass) {
// TODO Auto-generated method stub
return null;
}
@Override
public Class<? extends Config> getConfigClass(String subjectClassKey, String configKey) {
// TODO Auto-generated method stub
return null;
}
@Override
public <S> Set<S> getSubjects(Class<S> subjectClass) {
// TODO Auto-generated method stub
return null;
}
@Override
public <S, C extends Config<S>> Set<S> getSubjects(Class<S> subjectClass, Class<C> configClass) {
// TODO Auto-generated method stub
return null;
}
@Override
public <S> Set<? extends Config<S>> getConfigs(S subject) {
// TODO Auto-generated method stub
return null;
}
@Override
public <S, C extends Config<S>> C applyConfig(S subject, Class<C> configClass, JsonNode json) {
// TODO Auto-generated method stub
return null;
}
@Override
public <S, C extends Config<S>> C applyConfig(String subjectClassKey, S subject, String configKey, JsonNode json) {
// TODO Auto-generated method stub
return null;
}
@Override
public <S> void removeConfig(String subjectClassKey, S subject, String configKey) {
// TODO Auto-generated method stub
}
@Override
public <S> void removeConfig(S subject) {
// TODO Auto-generated method stub
}
@Override
public <S> void removeConfig() {
// TODO Auto-generated method stub
}
}
package org.onosproject.pcelabelstore.util;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import org.onosproject.incubator.net.tunnel.DefaultLabelStack;
import org.onosproject.incubator.net.tunnel.LabelStack;
import org.onosproject.incubator.net.tunnel.Tunnel;
import org.onosproject.net.Path;
import org.onosproject.pcep.controller.PccId;
import org.onosproject.pcep.controller.PcepClient;
import org.onosproject.pcep.controller.PcepClientController;
import org.onosproject.pcep.controller.PcepClientListener;
import org.onosproject.pcep.controller.PcepEventListener;
import org.onosproject.pcep.controller.PcepNodeListener;
import org.onosproject.pcepio.protocol.PcepMessage;
import org.onosproject.pcepio.types.PcepValueType;
public class MockPcepClientController implements PcepClientController {
Map<PccId, PcepClient> clientMap = new HashMap<>();
@Override
public Collection<PcepClient> getClients() {
// TODO Auto-generated method stub
return null;
}
public void addClient(PccId pccId, PcepClient pc) {
clientMap.put(pccId, pc);
return;
}
@Override
public PcepClient getClient(PccId pccId) {
return clientMap.get(pccId);
}
@Override
public void addListener(PcepClientListener listener) {
// TODO Auto-generated method stub
}
@Override
public void removeListener(PcepClientListener listener) {
// TODO Auto-generated method stub
}
@Override
public void addEventListener(PcepEventListener listener) {
// TODO Auto-generated method stub
}
@Override
public void removeEventListener(PcepEventListener listener) {
// TODO Auto-generated method stub
}
@Override
public void addNodeListener(PcepNodeListener listener) {
// TODO Auto-generated method stub
}
@Override
public void removeNodeListener(PcepNodeListener listener) {
// TODO Auto-generated method stub
}
@Override
public void writeMessage(PccId pccId, PcepMessage msg) {
// TODO Auto-generated method stub
}
@Override
public void processClientMessage(PccId pccId, PcepMessage msg) {
// TODO Auto-generated method stub
}
@Override
public void closeConnectedClients() {
// TODO Auto-generated method stub
}
@Override
public LabelStack computeLabelStack(Path path) {
// TODO Auto-generated method stub
return null;
}
@Override
public LinkedList<PcepValueType> createPcepLabelStack(DefaultLabelStack labelStack, Path path) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean allocateLocalLabel(Tunnel tunnel) {
// TODO Auto-generated method stub
return false;
}
}
/*
* 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.pcelabelstore.util;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.onosproject.incubator.net.resource.label.LabelResourceId;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.pcelabelstore.api.LspLocalLabelInfo;
import org.onosproject.pcelabelstore.api.PceLabelStore;
/**
* Provides test implementation of PceStore.
*/
public class PceLabelStoreAdapter implements PceLabelStore {
// Mapping device with global node label
private ConcurrentMap<DeviceId, LabelResourceId> globalNodeLabelMap = new ConcurrentHashMap<>();
// Mapping link with adjacency label
private ConcurrentMap<Link, LabelResourceId> adjLabelMap = new ConcurrentHashMap<>();
// Mapping tunnel with device local info with tunnel consumer id
private ConcurrentMap<TunnelId, List<LspLocalLabelInfo>> tunnelInfoMap = new ConcurrentHashMap<>();
// Locally maintain LSRID to device id mapping for better performance.
private Map<String, DeviceId> lsrIdDeviceIdMap = new HashMap<>();
@Override
public boolean existsGlobalNodeLabel(DeviceId id) {
return globalNodeLabelMap.containsKey(id);
}
@Override
public boolean existsAdjLabel(Link link) {
return adjLabelMap.containsKey(link);
}
@Override
public boolean existsTunnelInfo(TunnelId tunnelId) {
return tunnelInfoMap.containsKey(tunnelId);
}
@Override
public int getGlobalNodeLabelCount() {
return globalNodeLabelMap.size();
}
@Override
public int getAdjLabelCount() {
return adjLabelMap.size();
}
@Override
public int getTunnelInfoCount() {
return tunnelInfoMap.size();
}
@Override
public boolean removeTunnelInfo(TunnelId tunnelId) {
tunnelInfoMap.remove(tunnelId);
if (tunnelInfoMap.containsKey(tunnelId)) {
return false;
}
return true;
}
@Override
public Map<DeviceId, LabelResourceId> getGlobalNodeLabels() {
return globalNodeLabelMap.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue()));
}
@Override
public Map<Link, LabelResourceId> getAdjLabels() {
return adjLabelMap.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue()));
}
@Override
public LabelResourceId getGlobalNodeLabel(DeviceId id) {
return globalNodeLabelMap.get(id);
}
@Override
public LabelResourceId getAdjLabel(Link link) {
return adjLabelMap.get(link);
}
@Override
public List<LspLocalLabelInfo> getTunnelInfo(TunnelId tunnelId) {
return tunnelInfoMap.get(tunnelId);
}
@Override
public void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId) {
globalNodeLabelMap.put(deviceId, labelId);
}
@Override
public void addAdjLabel(Link link, LabelResourceId labelId) {
adjLabelMap.put(link, labelId);
}
@Override
public void addTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList) {
tunnelInfoMap.put(tunnelId, lspLocalLabelInfoList);
}
@Override
public boolean removeGlobalNodeLabel(DeviceId id) {
globalNodeLabelMap.remove(id);
if (globalNodeLabelMap.containsKey(id)) {
return false;
}
return true;
}
@Override
public boolean removeAdjLabel(Link link) {
adjLabelMap.remove(link);
if (adjLabelMap.containsKey(link)) {
return false;
}
return true;
}
@Override
public boolean addLsrIdDevice(String lsrId, DeviceId deviceId) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean removeLsrIdDevice(String lsrId) {
// TODO Auto-generated method stub
return false;
}
@Override
public DeviceId getLsrIdDevice(String lsrId) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean addPccLsr(DeviceId lsrId) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean removePccLsr(DeviceId lsrId) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean hasPccLsr(DeviceId lsrId) {
// TODO Auto-generated method stub
return false;
}
@Override
public Map<TunnelId, List<LspLocalLabelInfo>> getTunnelInfos() {
return tunnelInfoMap.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue()));
}
}
/*
* 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.pcelabelstore.util;
import static org.junit.Assert.assertNotNull;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.RejectedExecutionException;
import org.jboss.netty.channel.Channel;
import org.onosproject.pcep.controller.ClientCapability;
import org.onosproject.pcep.controller.PccId;
import org.onosproject.pcep.controller.LspKey;
import org.onosproject.pcep.controller.PcepClient;
import org.onosproject.pcep.controller.PcepSyncStatus;
import org.onosproject.pcepio.protocol.PcepFactories;
import org.onosproject.pcepio.protocol.PcepFactory;
import org.onosproject.pcepio.protocol.PcepMessage;
import org.onosproject.pcepio.protocol.PcepStateReport;
import org.onosproject.pcepio.protocol.PcepVersion;
/**
* Representation of PCEP client adapter.
*/
public class PcepClientAdapter implements PcepClient {
private Channel channel;
protected String channelId;
private boolean connected;
private PccId pccId;
private ClientCapability capability;
private PcepVersion pcepVersion;
private PcepSyncStatus lspDbSyncStatus;
private PcepSyncStatus labelDbSyncStatus;
private Map<LspKey, Boolean> lspDelegationInfo = new HashMap<>();
/**
* Initialize instance with specified parameters.
*
* @param pccId PCC id
* @param pcepVersion PCEP message version
*/
public void init(PccId pccId, PcepVersion pcepVersion) {
this.pccId = pccId;
this.pcepVersion = pcepVersion;
}
@Override
public final void disconnectClient() {
this.channel.close();
}
@Override
public final void sendMessage(PcepMessage m) {
}
@Override
public final void sendMessage(List<PcepMessage> msgs) {
try {
PcepMessage pcepMsg = msgs.get(0);
assertNotNull("PCEP MSG should be created.", pcepMsg);
} catch (RejectedExecutionException e) {
throw e;
}
}
@Override
public final boolean isConnected() {
return this.connected;
}
@Override
public String channelId() {
return channelId;
}
@Override
public final PccId getPccId() {
return this.pccId;
};
@Override
public final String getStringId() {
return this.pccId.toString();
}
@Override
public final void handleMessage(PcepMessage m) {
}
@Override
public boolean isOptical() {
return false;
}
@Override
public PcepFactory factory() {
return PcepFactories.getFactory(pcepVersion);
}
@Override
public void setLspDbSyncStatus(PcepSyncStatus syncStatus) {
this.lspDbSyncStatus = syncStatus;
}
@Override
public PcepSyncStatus lspDbSyncStatus() {
return lspDbSyncStatus;
}
@Override
public void setLabelDbSyncStatus(PcepSyncStatus syncStatus) {
this.labelDbSyncStatus = syncStatus;
}
@Override
public PcepSyncStatus labelDbSyncStatus() {
return labelDbSyncStatus;
}
@Override
public void setCapability(ClientCapability capability) {
this.capability = capability;
}
@Override
public ClientCapability capability() {
return capability;
}
@Override
public void addNode(PcepClient pc) {
}
@Override
public void deleteNode(PccId pccId) {
}
@Override
public void setLspAndDelegationInfo(LspKey lspKey, boolean dFlag) {
lspDelegationInfo.put(lspKey, dFlag);
}
@Override
public Boolean delegationInfo(LspKey lspKey) {
return lspDelegationInfo.get(lspKey);
}
@Override
public void initializeSyncMsgList(PccId pccId) {
// TODO Auto-generated method stub
}
@Override
public List<PcepStateReport> getSyncMsgList(PccId pccId) {
// TODO Auto-generated method stub
return null;
}
@Override
public void removeSyncMsgList(PccId pccId) {
// TODO Auto-generated method stub
}
@Override
public void addSyncMsgToList(PccId pccId, PcepStateReport rptMsg) {
// TODO Auto-generated method stub
}
}
/*
* Copyright 2015-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.pcelabelstore.util;
import org.onosproject.store.service.AtomicCounterBuilder;
import org.onosproject.store.service.AtomicValueBuilder;
import org.onosproject.store.service.ConsistentMapBuilder;
import org.onosproject.store.service.ConsistentTreeMapBuilder;
import org.onosproject.store.service.DistributedSetBuilder;
import org.onosproject.store.service.EventuallyConsistentMapBuilder;
import org.onosproject.store.service.LeaderElectorBuilder;
import org.onosproject.store.service.Serializer;
import org.onosproject.store.service.StorageService;
import org.onosproject.store.service.Topic;
import org.onosproject.store.service.TransactionContextBuilder;
import org.onosproject.store.service.WorkQueue;
/**
* Adapter for the storage service.
*/
public class StorageServiceAdapter implements StorageService {
@Override
public <K, V> EventuallyConsistentMapBuilder<K, V> eventuallyConsistentMapBuilder() {
return null;
}
@Override
public <K, V> ConsistentMapBuilder<K, V> consistentMapBuilder() {
return null;
}
@Override
public <E> DistributedSetBuilder<E> setBuilder() {
return null;
}
@Override
public AtomicCounterBuilder atomicCounterBuilder() {
return null;
}
@Override
public <V> AtomicValueBuilder<V> atomicValueBuilder() {
return null;
}
@Override
public TransactionContextBuilder transactionContextBuilder() {
return null;
}
@Override
public LeaderElectorBuilder leaderElectorBuilder() {
return null;
}
@Override
public <E> WorkQueue<E> getWorkQueue(String name, Serializer serializer) {
return null;
}
@Override
public <T> Topic<T> getTopic(String name, Serializer serializer) {
// TODO Auto-generated method stub
return null;
}
@Override
public <V> ConsistentTreeMapBuilder<V> consistentTreeMapBuilder() {
// TODO Auto-generated method stub
return null;
}
}
/*
* Copyright 2015-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.pcelabelstore.util;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicLong;
import org.onosproject.store.service.AsyncAtomicCounter;
import org.onosproject.store.service.AtomicCounterBuilder;
/**
* Test implementation of atomic counter.
*/
public final class TestAtomicCounter implements AsyncAtomicCounter {
final AtomicLong value;
@Override
public String name() {
return null;
}
private TestAtomicCounter() {
value = new AtomicLong();
}
@Override
public CompletableFuture<Long> incrementAndGet() {
return CompletableFuture.completedFuture(value.incrementAndGet());
}
@Override
public CompletableFuture<Long> getAndIncrement() {
return CompletableFuture.completedFuture(value.getAndIncrement());
}
@Override
public CompletableFuture<Long> getAndAdd(long delta) {
return CompletableFuture.completedFuture(value.getAndAdd(delta));
}
@Override
public CompletableFuture<Long> addAndGet(long delta) {
return CompletableFuture.completedFuture(value.addAndGet(delta));
}
@Override
public CompletableFuture<Void> set(long value) {
this.value.set(value);
return CompletableFuture.completedFuture(null);
}
@Override
public CompletableFuture<Boolean> compareAndSet(long expectedValue, long updateValue) {
return CompletableFuture.completedFuture(value.compareAndSet(expectedValue, updateValue));
}
@Override
public CompletableFuture<Long> get() {
return CompletableFuture.completedFuture(value.get());
}
public static AtomicCounterBuilder builder() {
return new Builder();
}
public static class Builder extends AtomicCounterBuilder {
@Override
public AsyncAtomicCounter build() {
return new TestAtomicCounter();
}
}
}
/*
* Copyright 2015-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.pcelabelstore.util;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.onosproject.store.primitives.ConsistentMapBackedJavaMap;
import org.onosproject.store.service.AsyncConsistentMap;
import org.onosproject.store.service.ConsistentMap;
import org.onosproject.store.service.ConsistentMapBuilder;
import org.onosproject.store.service.MapEvent;
import org.onosproject.store.service.MapEventListener;
import org.onosproject.store.service.Versioned;
import com.google.common.base.Objects;
/**
* Test implementation of the consistent map.
*/
public final class TestConsistentMap<K, V> extends ConsistentMapAdapter<K, V> {
private final List<MapEventListener<K, V>> listeners;
private final Map<K, Versioned<V>> map;
private final String mapName;
private final AtomicLong counter = new AtomicLong(0);
private TestConsistentMap(String mapName) {
map = new HashMap<>();
listeners = new LinkedList<>();
this.mapName = mapName;
}
private Versioned<V> version(V v) {
return new Versioned<>(v, counter.incrementAndGet(), System.currentTimeMillis());
}
/**
* Notify all listeners of an event.
*/
private void notifyListeners(String mapName,
K key, Versioned<V> newvalue, Versioned<V> oldValue) {
MapEvent<K, V> event = new MapEvent<>(mapName, key, newvalue, oldValue);
listeners.forEach(
listener -> listener.event(event)
);
}
@Override
public int size() {
return map.size();
}
@Override
public boolean isEmpty() {
return map.isEmpty();
}
@Override
public boolean containsKey(K key) {
return map.containsKey(key);
}
@Override
public boolean containsValue(V value) {
return map.containsValue(value);
}
@Override
public Versioned<V> get(K key) {
return map.get(key);
}
@Override
public Versioned<V> computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
AtomicBoolean updated = new AtomicBoolean(false);
Versioned<V> result = map.compute(key, (k, v) -> {
if (v == null) {
updated.set(true);
return version(mappingFunction.apply(key));
}
return v;
});
if (updated.get()) {
notifyListeners(mapName, key, result, null);
}
return result;
}
@Override
public Versioned<V> compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
AtomicBoolean updated = new AtomicBoolean(false);
AtomicReference<Versioned<V>> previousValue = new AtomicReference<>();
Versioned<V> result = map.compute(key, (k, v) -> {
updated.set(true);
previousValue.set(v);
return version(remappingFunction.apply(k, Versioned.valueOrNull(v)));
});
if (updated.get()) {
notifyListeners(mapName, key, result, previousValue.get());
}
return result;
}
@Override
public Versioned<V> computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
AtomicBoolean updated = new AtomicBoolean(false);
AtomicReference<Versioned<V>> previousValue = new AtomicReference<>();
Versioned<V> result = map.compute(key, (k, v) -> {
if (v != null) {
updated.set(true);
previousValue.set(v);
return version(remappingFunction.apply(k, v.value()));
}
return v;
});
if (updated.get()) {
notifyListeners(mapName, key, result, previousValue.get());
}
return result;
}
@Override
public Versioned<V> computeIf(K key, Predicate<? super V> condition,
BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
AtomicBoolean updated = new AtomicBoolean(false);
AtomicReference<Versioned<V>> previousValue = new AtomicReference<>();
Versioned<V> result = map.compute(key, (k, v) -> {
if (condition.test(Versioned.valueOrNull(v))) {
previousValue.set(v);
updated.set(true);
return version(remappingFunction.apply(k, Versioned.valueOrNull(v)));
}
return v;
});
if (updated.get()) {
notifyListeners(mapName, key, result, previousValue.get());
}
return result;
}
@Override
public Versioned<V> put(K key, V value) {
Versioned<V> newValue = version(value);
Versioned<V> previousValue = map.put(key, newValue);
notifyListeners(mapName, key, newValue, previousValue);
return previousValue;
}
@Override
public Versioned<V> putAndGet(K key, V value) {
Versioned<V> newValue = version(value);
Versioned<V> previousValue = map.put(key, newValue);
notifyListeners(mapName, key, newValue, previousValue);
return newValue;
}
@Override
public Versioned<V> remove(K key) {
Versioned<V> result = map.remove(key);
notifyListeners(mapName, key, null, result);
return result;
}
@Override
public void clear() {
map.keySet().forEach(this::remove);
}
@Override
public Set<K> keySet() {
return map.keySet();
}
@Override
public Collection<Versioned<V>> values() {
return map.values()
.stream()
.collect(Collectors.toList());
}
@Override
public Set<Map.Entry<K, Versioned<V>>> entrySet() {
return map.entrySet();
}
@Override
public Versioned<V> putIfAbsent(K key, V value) {
Versioned<V> newValue = version(value);
Versioned<V> result = map.putIfAbsent(key, newValue);
if (result == null) {
notifyListeners(mapName, key, newValue, result);
}
return result;
}
@Override
public boolean remove(K key, V value) {
Versioned<V> existingValue = map.get(key);
if (Objects.equal(Versioned.valueOrNull(existingValue), value)) {
map.remove(key);
notifyListeners(mapName, key, null, existingValue);
return true;
}
return false;
}
@Override
public boolean remove(K key, long version) {
Versioned<V> existingValue = map.get(key);
if (existingValue == null) {
return false;
}
if (existingValue.version() == version) {
map.remove(key);
notifyListeners(mapName, key, null, existingValue);
return true;
}
return false;
}
@Override
public Versioned<V> replace(K key, V value) {
Versioned<V> existingValue = map.get(key);
if (existingValue == null) {
return null;
}
Versioned<V> newValue = version(value);
Versioned<V> result = map.put(key, newValue);
notifyListeners(mapName, key, newValue, result);
return result;
}
@Override
public boolean replace(K key, V oldValue, V newValue) {
Versioned<V> existingValue = map.get(key);
if (existingValue == null || !existingValue.value().equals(oldValue)) {
return false;
}
Versioned<V> value = version(newValue);
Versioned<V> result = map.put(key, value);
notifyListeners(mapName, key, value, result);
return true;
}
@Override
public boolean replace(K key, long oldVersion, V newValue) {
Versioned<V> existingValue = map.get(key);
if (existingValue == null || existingValue.version() != oldVersion) {
return false;
}
Versioned<V> value = version(newValue);
Versioned<V> result = map.put(key, value);
notifyListeners(mapName, key, value, result);
return true;
}
@Override
public void addListener(MapEventListener<K, V> listener) {
listeners.add(listener);
}
@Override
public void removeListener(MapEventListener<K, V> listener) {
listeners.remove(listener);
}
@Override
public Map<K, V> asJavaMap() {
return new ConsistentMapBackedJavaMap<>(this);
}
public static Builder builder() {
return new Builder();
}
public static class Builder<K, V> extends ConsistentMapBuilder<K, V> {
@Override
public ConsistentMap<K, V> build() {
return new TestConsistentMap<>(name());
}
@Override
public AsyncConsistentMap<K, V> buildAsyncMap() {
return null;
}
}
}
/*
* 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.pcelabelstore.util;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.onosproject.store.primitives.DefaultDistributedSet;
import org.onosproject.store.service.AsyncDistributedSet;
import org.onosproject.store.service.DistributedSet;
import org.onosproject.store.service.DistributedSetBuilder;
import org.onosproject.store.service.SetEvent;
import org.onosproject.store.service.SetEventListener;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
/**
* Test implementation of the distributed set.
*/
public final class TestDistributedSet<E> extends DistributedSetAdapter<E> {
private final List<SetEventListener<E>> listeners;
private final Set<E> set;
private final String setName;
/**
* Public constructor.
*
* @param setName name to be assigned to this set
*/
public TestDistributedSet(String setName) {
set = new HashSet<>();
listeners = new LinkedList<>();
this.setName = setName;
}
/**
* Notify all listeners of a set event.
*
* @param event the SetEvent
*/
private void notifyListeners(SetEvent<E> event) {
listeners.forEach(
listener -> listener.event(event)
);
}
@Override
public CompletableFuture<Void> addListener(SetEventListener<E> listener) {
listeners.add(listener);
return CompletableFuture.completedFuture(null);
}
@Override
public CompletableFuture<Void> removeListener(SetEventListener<E> listener) {
listeners.remove(listener);
return CompletableFuture.completedFuture(null);
}
@Override
public CompletableFuture<Boolean> add(E element) {
SetEvent<E> event =
new SetEvent<>(setName, SetEvent.Type.ADD, element);
notifyListeners(event);
return CompletableFuture.completedFuture(set.add(element));
}
@Override
public CompletableFuture<Boolean> remove(E element) {
SetEvent<E> event =
new SetEvent<>(setName, SetEvent.Type.REMOVE, element);
notifyListeners(event);
return CompletableFuture.completedFuture(set.remove(element));
}
@Override
public CompletableFuture<Integer> size() {
return CompletableFuture.completedFuture(set.size());
}
@Override
public CompletableFuture<Boolean> isEmpty() {
return CompletableFuture.completedFuture(set.isEmpty());
}
@Override
public CompletableFuture<Void> clear() {
removeAll(ImmutableSet.copyOf(set));
return CompletableFuture.completedFuture(null);
}
@Override
public CompletableFuture<Boolean> contains(E element) {
return CompletableFuture.completedFuture(set.contains(element));
}
@Override
public CompletableFuture<Boolean> addAll(Collection<? extends E> c) {
c.forEach(this::add);
return CompletableFuture.completedFuture(true);
}
@Override
public CompletableFuture<Boolean> containsAll(Collection<? extends E> c) {
return CompletableFuture.completedFuture(set.containsAll(c));
}
@Override
public CompletableFuture<Boolean> retainAll(Collection<? extends E> c) {
Set notInSet2;
notInSet2 = Sets.difference(set, (Set<?>) c);
return removeAll(ImmutableSet.copyOf(notInSet2));
}
@Override
public CompletableFuture<Boolean> removeAll(Collection<? extends E> c) {
c.forEach(this::remove);
return CompletableFuture.completedFuture(true);
}
@Override
public CompletableFuture<? extends Set<E>> getAsImmutableSet() {
return CompletableFuture.completedFuture(ImmutableSet.copyOf(set));
}
@Override
public String name() {
return this.setName;
}
@Override
public DistributedSet<E> asDistributedSet() {
return new DefaultDistributedSet<>(this, 0);
}
@Override
public DistributedSet<E> asDistributedSet(long timeoutMillis) {
return new DefaultDistributedSet<>(this, timeoutMillis);
}
/**
* Returns a new Builder instance.
*
* @return Builder
**/
public static Builder builder() {
return new Builder();
}
/**
* Builder constructor that instantiates a TestDistributedSet.
*
* @param <E>
*/
public static class Builder<E> extends DistributedSetBuilder<E> {
@Override
public AsyncDistributedSet<E> build() {
return new TestDistributedSet(name());
}
}
}
/*
* Copyright 2015-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.pcelabelstore.util;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.BiFunction;
import org.onlab.util.KryoNamespace;
import org.onosproject.cluster.NodeId;
import org.onosproject.store.Timestamp;
import org.onosproject.store.service.EventuallyConsistentMap;
import org.onosproject.store.service.EventuallyConsistentMapBuilder;
import org.onosproject.store.service.EventuallyConsistentMapEvent;
import org.onosproject.store.service.EventuallyConsistentMapListener;
import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT;
import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.REMOVE;
/**
* Testing version of an Eventually Consistent Map.
*/
public final class TestEventuallyConsistentMap<K, V> extends EventuallyConsistentMapAdapter<K, V> {
private final HashMap<K, V> map;
private final String mapName;
private final List<EventuallyConsistentMapListener<K, V>> listeners;
private final BiFunction<K, V, Collection<NodeId>> peerUpdateFunction;
private TestEventuallyConsistentMap(String mapName,
BiFunction<K, V, Collection<NodeId>> peerUpdateFunction) {
map = new HashMap<>();
listeners = new LinkedList<>();
this.mapName = mapName;
this.peerUpdateFunction = peerUpdateFunction;
}
/**
* Notify all listeners of an event.
*/
private void notifyListeners(EventuallyConsistentMapEvent<K, V> event) {
listeners.forEach(
listener -> listener.event(event)
);
}
@Override
public int size() {
return map.size();
}
@Override
public boolean isEmpty() {
return map.isEmpty();
}
@Override
public boolean containsKey(K key) {
return map.containsKey(key);
}
@Override
public boolean containsValue(V value) {
return map.containsValue(value);
}
@Override
public V get(K key) {
return map.get(key);
}
@Override
public void put(K key, V value) {
map.put(key, value);
EventuallyConsistentMapEvent<K, V> addEvent =
new EventuallyConsistentMapEvent<>(mapName, PUT, key, value);
notifyListeners(addEvent);
if (peerUpdateFunction != null) {
peerUpdateFunction.apply(key, value);
}
}
@Override
public V remove(K key) {
V result = map.remove(key);
if (result != null) {
EventuallyConsistentMapEvent<K, V> removeEvent =
new EventuallyConsistentMapEvent<>(mapName, REMOVE,
key, map.get(key));
notifyListeners(removeEvent);
}
return result;
}
@Override
public void remove(K key, V value) {
boolean removed = map.remove(key, value);
if (removed) {
EventuallyConsistentMapEvent<K, V> removeEvent =
new EventuallyConsistentMapEvent<>(mapName, REMOVE, key, value);
notifyListeners(removeEvent);
}
}
@Override
public V compute(K key, BiFunction<K, V, V> recomputeFunction) {
return map.compute(key, recomputeFunction);
}
@Override
public void putAll(Map<? extends K, ? extends V> m) {
map.putAll(m);
}
@Override
public void clear() {
map.clear();
}
@Override
public Set<K> keySet() {
return map.keySet();
}
@Override
public Collection<V> values() {
return map.values();
}
@Override
public Set<Map.Entry<K, V>> entrySet() {
return map.entrySet();
}
public static <K, V> Builder<K, V> builder() {
return new Builder<>();
}
@Override
public void addListener(EventuallyConsistentMapListener<K, V> listener) {
listeners.add(listener);
}
@Override
public void removeListener(EventuallyConsistentMapListener<K, V> listener) {
listeners.remove(listener);
}
public static class Builder<K, V> implements EventuallyConsistentMapBuilder<K, V> {
private String name;
private BiFunction<K, V, Collection<NodeId>> peerUpdateFunction;
@Override
public EventuallyConsistentMapBuilder<K, V> withName(String name) {
this.name = name;
return this;
}
@Override
public EventuallyConsistentMapBuilder<K, V> withSerializer(KryoNamespace.Builder serializerBuilder) {
return this;
}
@Override
public EventuallyConsistentMapBuilder<K, V> withSerializer(KryoNamespace serializer) {
return this;
}
@Override
public EventuallyConsistentMapBuilder<K, V>
withTimestampProvider(BiFunction<K, V, Timestamp> timestampProvider) {
return this;
}
@Override
public EventuallyConsistentMapBuilder<K, V> withEventExecutor(ExecutorService executor) {
return this;
}
@Override
public EventuallyConsistentMapBuilder<K, V> withCommunicationExecutor(ExecutorService executor) {
return this;
}
@Override
public EventuallyConsistentMapBuilder<K, V> withBackgroundExecutor(ScheduledExecutorService executor) {
return this;
}
@Override
public EventuallyConsistentMapBuilder<K, V>
withPeerUpdateFunction(BiFunction<K, V, Collection<NodeId>> peerUpdateFunction) {
this.peerUpdateFunction = peerUpdateFunction;
return this;
}
@Override
public EventuallyConsistentMapBuilder<K, V> withTombstonesDisabled() {
return this;
}
@Override
public EventuallyConsistentMapBuilder<K, V> withAntiEntropyPeriod(long period, TimeUnit unit) {
return this;
}
@Override
public EventuallyConsistentMapBuilder<K, V> withFasterConvergence() {
return this;
}
@Override
public EventuallyConsistentMapBuilder<K, V> withPersistence() {
return this;
}
@Override
public EventuallyConsistentMap<K, V> build() {
if (name == null) {
name = "test";
}
return new TestEventuallyConsistentMap<>(name, peerUpdateFunction);
}
}
}
/*
* Copyright 2016-present Open Networking Laboratory
* Copyright 2015-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.
......@@ -13,58 +13,45 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.pce.util;
package org.onosproject.pcelabelstore.util;
import java.util.List;
import com.google.common.collect.ImmutableList;
import org.onosproject.net.DeviceId;
import org.onosproject.net.flowobjective.FilteringObjective;
import org.onosproject.net.flowobjective.FlowObjectiveService;
import org.onosproject.net.flowobjective.ForwardingObjective;
import org.onosproject.net.flowobjective.NextObjective;
import org.onosproject.store.service.AtomicCounterBuilder;
import org.onosproject.store.service.AtomicValueBuilder;
import org.onosproject.store.service.ConsistentMapBuilder;
import org.onosproject.store.service.DistributedSetBuilder;
import org.onosproject.store.service.EventuallyConsistentMapBuilder;
import org.onosproject.store.service.TransactionContextBuilder;
/**
* Test implementation of FlowObjectiveService.
*/
public class FlowObjServiceAdapter implements FlowObjectiveService {
private ForwardingObjective forwardingObjective;
@Override
public void filter(DeviceId deviceId, FilteringObjective filteringObjective) {
public class TestStorageService extends StorageServiceAdapter {
}
@Override
public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) {
this.forwardingObjective = forwardingObjective;
public <K, V> EventuallyConsistentMapBuilder<K, V> eventuallyConsistentMapBuilder() {
return TestEventuallyConsistentMap.builder();
}
@Override
public void next(DeviceId deviceId, NextObjective nextObjective) {
public <K, V> ConsistentMapBuilder<K, V> consistentMapBuilder() {
return TestConsistentMap.builder();
}
@Override
public int allocateNextId() {
return 0;
public <E> DistributedSetBuilder<E> setBuilder() {
return TestDistributedSet.builder();
}
@Override
public void initPolicy(String policy) {
}
public ForwardingObjective forwardingObjective() {
return forwardingObjective;
public AtomicCounterBuilder atomicCounterBuilder() {
return TestAtomicCounter.builder();
}
@Override
public List<String> getNextMappings() {
return ImmutableList.of();
public <V> AtomicValueBuilder<V> atomicValueBuilder() {
throw new UnsupportedOperationException("atomicValueBuilder");
}
@Override
public List<String> getPendingNexts() {
return ImmutableList.of();
public TransactionContextBuilder transactionContextBuilder() {
throw new UnsupportedOperationException("transactionContextBuilder");
}
}
......
......@@ -366,7 +366,6 @@ public class PcepLspObjectVer1 implements PcepLspObject {
default:
// Skip the unknown TLV.
cb.skipBytes(hLength);
tlv = null;
log.info("Received unsupported TLV type :" + hType + " in LSP object.");
}
// Check for the padding
......
......@@ -22,6 +22,15 @@
<artifact>mvn:${project.groupId}/onos-bgpio/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-bgp-api/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-bgp-ctl/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-pcep-controller-api/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-bgp-provider-topology/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-bgp-provider-cfg/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-pcepio/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-app-pcep-api/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-pcep-controller-impl/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-pcep-provider-topology/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-pcep-provider-tunnel/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-app-pce/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-app-pceweb/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-app-pcerest/${project.version}</artifact>
</app>
......
......@@ -21,7 +21,16 @@
<bundle>mvn:${project.groupId}/onos-bgpio/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-bgp-api/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-bgp-ctl/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-pcep-controller-api/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-bgp-provider-topology/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-bgp-provider-cfg/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-pcepio/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-app-pcep-api/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-pcep-controller-impl/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-pcep-provider-topology/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-pcep-provider-tunnel/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-app-pce/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-app-pceweb/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-app-pcerest/${project.version}</bundle>
</feature>
</features>
......
......@@ -46,5 +46,20 @@
<artifactId>onos-bgp-provider-topology</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-pce</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-pceweb</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-pcerest</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
......
......@@ -10,7 +10,6 @@ BUNDLES = [
'//protocols/pcep/ctl:onos-protocols-pcep-ctl',
'//providers/pcep/topology:onos-providers-pcep-topology',
'//providers/pcep/tunnel:onos-providers-pcep-tunnel',
'//providers/pcep/packet:onos-providers-pcep-packet',
'//providers/bgpcep/flow:onos-providers-bgpcep-flow',
'//apps/pce/app:onos-apps-pce-app',
'//apps/pce/pceweb:onos-apps-pce-pceweb',
......
......@@ -30,7 +30,6 @@
<artifact>mvn:${project.groupId}/onos-pcep-controller-impl/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-pcep-provider-topology/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-pcep-provider-tunnel/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-pcep-provider-packet/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-bgpcep-provider-flow/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-app-pce/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-app-pceweb/${project.version}</artifact>
......
......@@ -31,7 +31,6 @@
<bundle>mvn:${project.groupId}/onos-pcep-provider-tunnel/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-app-pce/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-app-pceweb/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-pcep-provider-packet/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-bgpcep-provider-flow/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-app-pcerest/${project.version}</bundle>
</feature>
......
......@@ -15,95 +15,22 @@
*/
package org.onosproject.provider.bgpcep.flow.impl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
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.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MplsLabel;
import org.onosproject.bgp.controller.BgpController;
import org.onosproject.core.ApplicationId;
import org.onosproject.incubator.net.resource.label.LabelResourceId;
import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
import org.onosproject.incubator.net.tunnel.Tunnel;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.incubator.net.tunnel.TunnelService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
import org.onosproject.net.PortNumber;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.flow.CompletedBatchOperation;
import org.onosproject.net.flow.DefaultFlowEntry;
import org.onosproject.net.flow.FlowEntry;
import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.FlowRuleBatchEntry;
import org.onosproject.net.flow.FlowRuleBatchOperation;
import org.onosproject.net.flow.FlowRuleProvider;
import org.onosproject.net.flow.FlowRuleProviderRegistry;
import org.onosproject.net.flow.FlowRuleProviderService;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.FlowEntry.FlowEntryState;
import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flow.criteria.IPCriterion;
import org.onosproject.net.flow.criteria.MetadataCriterion;
import org.onosproject.net.flow.criteria.MplsBosCriterion;
import org.onosproject.net.flow.criteria.MplsCriterion;
import org.onosproject.net.flow.criteria.PortCriterion;
import org.onosproject.net.flow.criteria.TunnelIdCriterion;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.net.resource.ResourceService;
import org.onosproject.pcep.controller.PccId;
import org.onosproject.pcep.controller.PcepClient;
import org.onosproject.pcep.controller.PcepClientController;
import org.onosproject.pcepio.exceptions.PcepParseException;
import org.onosproject.pcepio.protocol.PcepEroObject;
import org.onosproject.pcepio.protocol.PcepFecObjectIPv4;
import org.onosproject.pcepio.protocol.PcepFecObjectIPv4Adjacency;
import org.onosproject.pcepio.protocol.PcepLabelObject;
import org.onosproject.pcepio.protocol.PcepLabelUpdate;
import org.onosproject.pcepio.protocol.PcepLabelUpdateMsg;
import org.onosproject.pcepio.protocol.PcepLspObject;
import org.onosproject.pcepio.protocol.PcepMsgPath;
import org.onosproject.pcepio.protocol.PcepSrpObject;
import org.onosproject.pcepio.protocol.PcepUpdateMsg;
import org.onosproject.pcepio.protocol.PcepUpdateRequest;
import org.onosproject.pcepio.types.IPv4SubObject;
import org.onosproject.pcepio.types.NexthopIPv4addressTlv;
import org.onosproject.pcepio.types.PathSetupTypeTlv;
import org.onosproject.pcepio.types.PcepLabelDownload;
import org.onosproject.pcepio.types.PcepLabelMap;
import org.onosproject.pcepio.types.PcepValueType;
import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
import org.onosproject.pcepio.types.SymbolicPathNameTlv;
import org.onosproject.pcep.controller.LspType;
import org.onosproject.pcepio.protocol.PcepAttribute;
import org.onosproject.pcepio.protocol.PcepBandwidthObject;
import org.onosproject.pcep.controller.SrpIdGenerators;
import org.onosproject.pcep.controller.PcepAnnotationKeys;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import static org.onosproject.pcep.controller.PcepAnnotationKeys.BANDWIDTH;
import static org.onosproject.pcep.controller.PcepAnnotationKeys.DELEGATE;
import static org.onosproject.pcep.controller.PcepAnnotationKeys.LSP_SIG_TYPE;
import static org.onosproject.pcep.controller.PcepAnnotationKeys.PCE_INIT;
import static org.onosproject.pcep.controller.PcepSyncStatus.IN_SYNC;
import static org.onosproject.pcep.controller.PcepSyncStatus.SYNCED;
import static org.onosproject.net.flow.criteria.Criterion.Type.EXTENSION;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
/**
......@@ -118,34 +45,7 @@ public class BgpcepFlowRuleProvider extends AbstractProvider
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected FlowRuleProviderRegistry providerRegistry;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected BgpController bgpController;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected PcepClientController pcepController;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ResourceService resourceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected TunnelService tunnelService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceService deviceService;
private FlowRuleProviderService providerService;
private PcepLabelObject labelObj;
public static final int OUT_LABEL_TYPE = 0;
public static final int IN_LABEL_TYPE = 1;
public static final long IDENTIFIER_SET = 0x100000000L;
public static final long SET = 0xFFFFFFFFL;
private static final String LSRID = "lsrId";
private enum PcepFlowType {
ADD,
MODIFY,
REMOVE
}
/**
* Creates a BgpFlow host provider.
......@@ -169,469 +69,25 @@ public class BgpcepFlowRuleProvider extends AbstractProvider
@Override
public void applyFlowRule(FlowRule... flowRules) {
for (FlowRule flowRule : flowRules) {
processRule(flowRule, PcepFlowType.ADD);
}
// TODO Auto-generated method stub
}
@Override
public void removeFlowRule(FlowRule... flowRules) {
for (FlowRule flowRule : flowRules) {
processRule(flowRule, PcepFlowType.REMOVE);
}
}
// TODO Auto-generated method stub
private void processRule(FlowRule flowRule, PcepFlowType type) {
MplsLabel mplsLabel = null;
IpPrefix ip4PrefixSrc = null;
IpPrefix ip4PrefixDst = null;
PortNumber port = null;
TunnelId tunnelId = null;
long labelType = 0;
boolean bottomOfStack = false;
TrafficSelector selector = flowRule.selector();
for (Criterion c : selector.criteria()) {
switch (c.type()) {
case MPLS_LABEL:
MplsCriterion lc = (MplsCriterion) c;
mplsLabel = lc.label();
break;
case IPV4_SRC:
IPCriterion ipCriterion = (IPCriterion) c;
ip4PrefixSrc = ipCriterion.ip().getIp4Prefix();
break;
case IPV4_DST:
ipCriterion = (IPCriterion) c;
ip4PrefixDst = ipCriterion.ip().getIp4Prefix();
break;
case IN_PORT:
PortCriterion inPort = (PortCriterion) c;
port = inPort.port();
break;
case TUNNEL_ID:
TunnelIdCriterion tc = (TunnelIdCriterion) c;
tunnelId = TunnelId.valueOf(String.valueOf(tc.tunnelId()));
break;
case METADATA:
MetadataCriterion metadata = (MetadataCriterion) c;
labelType = metadata.metadata();
break;
case MPLS_BOS:
MplsBosCriterion mplsBos = (MplsBosCriterion) c;
bottomOfStack = mplsBos.mplsBos();
break;
default:
break;
}
}
checkNotNull(mplsLabel);
LabelResourceId label = LabelResourceId.labelResourceId(mplsLabel.toInt());
try {
if (tunnelId != null) {
pushLocalLabels(flowRule.deviceId(), label, port, tunnelId, bottomOfStack, labelType, type);
return;
}
if (ip4PrefixDst != null) {
pushAdjacencyLabel(flowRule.deviceId(), label, ip4PrefixSrc, ip4PrefixDst, type);
return;
}
pushGlobalNodeLabel(flowRule.deviceId(), label, ip4PrefixSrc, type, bottomOfStack);
} catch (PcepParseException e) {
log.error("Exception occured while sending label message to PCC {}", e.getMessage());
}
}
/**
* Returns PCEP client.
*
* @return PCEP client
*/
private PcepClient getPcepClient(DeviceId deviceId) {
Device device = deviceService.getDevice(deviceId);
// In future projections instead of annotations will be used to fetch LSR ID.
String lsrId = device.annotations().value(LSRID);
PcepClient pcc = pcepController.getClient(PccId.pccId(IpAddress.valueOf(lsrId)));
return pcc;
}
//Pushes node labels to the specified device.
private void pushGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId,
IpPrefix ipPrefix, PcepFlowType type, boolean isBos) throws PcepParseException {
checkNotNull(deviceId);
checkNotNull(labelId);
checkNotNull(type);
PcepClient pc = getPcepClient(deviceId);
if (pc == null) {
log.error("PCEP client not found");
return;
}
LinkedList<PcepLabelUpdate> labelUpdateList = new LinkedList<>();
if (ipPrefix == null) {
// Pushing self node label to device.
ipPrefix = IpPrefix.valueOf(pc.getPccId().ipAddress(), 32);
}
PcepFecObjectIPv4 fecObject = pc.factory().buildFecObjectIpv4()
.setNodeID(ipPrefix.address().getIp4Address().toInt())
.build();
boolean bSFlag = false;
if (pc.labelDbSyncStatus() == IN_SYNC && !isBos) {
// Need to set sync flag in all messages till sync completes.
bSFlag = true;
}
PcepSrpObject srpObj = getSrpObject(pc, type, bSFlag);
//Global NODE-SID as label object
PcepLabelObject labelObject = pc.factory().buildLabelObject()
.setLabel((int) labelId.labelId())
.build();
PcepLabelMap labelMap = new PcepLabelMap();
labelMap.setFecObject(fecObject);
labelMap.setLabelObject(labelObject);
labelMap.setSrpObject(srpObj);
labelUpdateList.add(pc.factory().buildPcepLabelUpdateObject()
.setLabelMap(labelMap)
.build());
PcepLabelUpdateMsg labelMsg = pc.factory().buildPcepLabelUpdateMsg()
.setPcLabelUpdateList(labelUpdateList)
.build();
pc.sendMessage(labelMsg);
if (isBos) {
// Sync is completed.
pc.setLabelDbSyncStatus(SYNCED);
}
}
private PcepSrpObject getSrpObject(PcepClient pc, PcepFlowType type, boolean bSFlag)
throws PcepParseException {
PcepSrpObject srpObj;
boolean bRFlag = false;
if (!type.equals(PcepFlowType.ADD)) {
// To cleanup labels, R bit is set
bRFlag = true;
}
srpObj = pc.factory().buildSrpObject()
.setRFlag(bRFlag)
.setSFlag(bSFlag)
.setSrpID(SrpIdGenerators.create())
.build();
return srpObj;
}
//Pushes adjacency labels to the specified device.
private void pushAdjacencyLabel(DeviceId deviceId, LabelResourceId labelId, IpPrefix ip4PrefixSrc,
IpPrefix ip4PrefixDst, PcepFlowType type)
throws PcepParseException {
checkNotNull(deviceId);
checkNotNull(labelId);
checkNotNull(ip4PrefixSrc);
checkNotNull(ip4PrefixDst);
checkNotNull(type);
PcepClient pc = getPcepClient(deviceId);
if (pc == null) {
log.error("PCEP client not found");
return;
}
LinkedList<PcepLabelUpdate> labelUpdateList = new LinkedList<>();
int srcPortNo = ip4PrefixSrc.address().getIp4Address().toInt();
int dstPortNo = ip4PrefixDst.address().getIp4Address().toInt();
PcepFecObjectIPv4Adjacency fecAdjObject = pc.factory().buildFecIpv4Adjacency()
.seRemoteIPv4Address(dstPortNo)
.seLocalIPv4Address(srcPortNo)
.build();
boolean bSFlag = false;
if (pc.labelDbSyncStatus() == IN_SYNC) {
// Need to set sync flag in all messages till sync completes.
bSFlag = true;
}
PcepSrpObject srpObj = getSrpObject(pc, type, bSFlag);
//Adjacency label object
PcepLabelObject labelObject = pc.factory().buildLabelObject()
.setLabel((int) labelId.labelId())
.build();
PcepLabelMap labelMap = new PcepLabelMap();
labelMap.setFecObject(fecAdjObject);
labelMap.setLabelObject(labelObject);
labelMap.setSrpObject(srpObj);
labelUpdateList.add(pc.factory().buildPcepLabelUpdateObject()
.setLabelMap(labelMap)
.build());
PcepLabelUpdateMsg labelMsg = pc.factory().buildPcepLabelUpdateMsg()
.setPcLabelUpdateList(labelUpdateList)
.build();
pc.sendMessage(labelMsg);
}
//Pushes local labels to the device which is specific to path [CR-case].
private void pushLocalLabels(DeviceId deviceId, LabelResourceId labelId,
PortNumber portNum, TunnelId tunnelId,
Boolean isBos, Long labelType, PcepFlowType type) throws PcepParseException {
checkNotNull(deviceId);
checkNotNull(labelId);
checkNotNull(portNum);
checkNotNull(tunnelId);
checkNotNull(labelType);
checkNotNull(type);
PcepClient pc = getPcepClient(deviceId);
if (pc == null) {
log.error("PCEP client not found");
return;
}
PcepLspObject lspObj;
LinkedList<PcepLabelUpdate> labelUpdateList = new LinkedList<>();
LinkedList<PcepLabelObject> labelObjects = new LinkedList<>();
PcepSrpObject srpObj;
PcepLabelDownload labelDownload = new PcepLabelDownload();
LinkedList<PcepValueType> optionalTlv = new LinkedList<>();
long portNo = portNum.toLong();
portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo;
optionalTlv.add(NexthopIPv4addressTlv.of((int) portNo));
Tunnel tunnel = tunnelService.queryTunnel(tunnelId);
PcepLabelObject labelObj = pc.factory().buildLabelObject()
.setOFlag(labelType == OUT_LABEL_TYPE)
.setOptionalTlv(optionalTlv)
.setLabel((int) labelId.labelId())
.build();
/**
* Check whether transit node or not. For transit node, label update message should include IN and OUT labels.
* Hence store IN label object and next when out label comes add IN and OUT label objects and encode label
* update message and send to specified client.
*/
if (!deviceId.equals(tunnel.path().src().deviceId()) && !deviceId.equals(tunnel.path().dst().deviceId())) {
//Device is transit node
if (labelType == IN_LABEL_TYPE) {
//Store label object having IN label value
this.labelObj = labelObj;
return;
}
//Add IN label object
labelObjects.add(this.labelObj);
}
//Add OUT label object in case of transit node
labelObjects.add(labelObj);
srpObj = getSrpObject(pc, type, false);
String lspId = tunnel.annotations().value(PcepAnnotationKeys.LOCAL_LSP_ID);
String plspId = tunnel.annotations().value(PcepAnnotationKeys.PLSP_ID);
String tunnelIdentifier = tunnel.annotations().value(PcepAnnotationKeys.PCC_TUNNEL_ID);
LinkedList<PcepValueType> tlvs = new LinkedList<>();
StatefulIPv4LspIdentifiersTlv lspIdTlv = new StatefulIPv4LspIdentifiersTlv(((IpTunnelEndPoint) tunnel.src())
.ip().getIp4Address().toInt(), Short.valueOf(lspId), Short.valueOf(tunnelIdentifier),
((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt(),
((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt());
tlvs.add(lspIdTlv);
if (tunnel.tunnelName().value() != null) {
SymbolicPathNameTlv pathNameTlv = new SymbolicPathNameTlv(tunnel.tunnelName().value().getBytes());
tlvs.add(pathNameTlv);
}
boolean delegated = (tunnel.annotations().value(DELEGATE) == null) ? false
: Boolean.valueOf(tunnel.annotations()
.value(DELEGATE));
boolean initiated = (tunnel.annotations().value(PCE_INIT) == null) ? false
: Boolean.valueOf(tunnel.annotations()
.value(PCE_INIT));
lspObj = pc.factory().buildLspObject()
.setRFlag(false)
.setAFlag(true)
.setDFlag(delegated)
.setCFlag(initiated)
.setPlspId(Integer.valueOf(plspId))
.setOptionalTlv(tlvs)
.build();
labelDownload.setLabelList(labelObjects);
labelDownload.setLspObject(lspObj);
labelDownload.setSrpObject(srpObj);
labelUpdateList.add(pc.factory().buildPcepLabelUpdateObject()
.setLabelDownload(labelDownload)
.build());
PcepLabelUpdateMsg labelMsg = pc.factory().buildPcepLabelUpdateMsg()
.setPcLabelUpdateList(labelUpdateList)
.build();
pc.sendMessage(labelMsg);
//If isBos is true, label download is done along the LSP, send PCEP update message.
if (isBos) {
sendPcepUpdateMsg(pc, lspObj, tunnel);
}
}
//Sends PCEP update message.
private void sendPcepUpdateMsg(PcepClient pc, PcepLspObject lspObj, Tunnel tunnel) throws PcepParseException {
LinkedList<PcepUpdateRequest> updateRequestList = new LinkedList<>();
LinkedList<PcepValueType> subObjects = createEroSubObj(tunnel.path());
if (subObjects == null) {
log.error("ERO subjects not present");
return;
}
// set PathSetupTypeTlv of SRP object
LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
LspType lspSigType = LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE));
llOptionalTlv.add(new PathSetupTypeTlv(lspSigType.type()));
PcepSrpObject srpObj = pc.factory().buildSrpObject()
.setRFlag(false)
.setSrpID(SrpIdGenerators.create())
.setOptionalTlv(llOptionalTlv)
.build();
PcepEroObject eroObj = pc.factory().buildEroObject()
.setSubObjects(subObjects)
.build();
float iBandwidth = 0;
if (tunnel.annotations().value(BANDWIDTH) != null) {
//iBandwidth = Float.floatToIntBits(Float.parseFloat(tunnel.annotations().value(BANDWIDTH)));
iBandwidth = Float.parseFloat(tunnel.annotations().value(BANDWIDTH));
}
// build bandwidth object
PcepBandwidthObject bandwidthObject = pc.factory().buildBandwidthObject()
.setBandwidth(iBandwidth)
.build();
// build pcep attribute
PcepAttribute pcepAttribute = pc.factory().buildPcepAttribute()
.setBandwidthObject(bandwidthObject)
.build();
PcepMsgPath msgPath = pc.factory().buildPcepMsgPath()
.setEroObject(eroObj)
.setPcepAttribute(pcepAttribute)
.build();
PcepUpdateRequest updateReq = pc.factory().buildPcepUpdateRequest()
.setSrpObject(srpObj)
.setMsgPath(msgPath)
.setLspObject(lspObj)
.build();
updateRequestList.add(updateReq);
//TODO: P = 1 is it P flag in PCEP obj header
PcepUpdateMsg updateMsg = pc.factory().buildUpdateMsg()
.setUpdateRequestList(updateRequestList)
.build();
pc.sendMessage(updateMsg);
}
private LinkedList<PcepValueType> createEroSubObj(Path path) {
LinkedList<PcepValueType> subObjects = new LinkedList<>();
List<Link> links = path.links();
ConnectPoint source = null;
ConnectPoint destination = null;
IpAddress ipDstAddress = null;
IpAddress ipSrcAddress = null;
PcepValueType subObj = null;
long portNo;
for (Link link : links) {
source = link.src();
if (!(source.equals(destination))) {
//set IPv4SubObject for ERO object
portNo = source.port().toLong();
portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo;
ipSrcAddress = Ip4Address.valueOf((int) portNo);
subObj = new IPv4SubObject(ipSrcAddress.getIp4Address().toInt());
subObjects.add(subObj);
}
destination = link.dst();
portNo = destination.port().toLong();
portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo;
ipDstAddress = Ip4Address.valueOf((int) portNo);
subObj = new IPv4SubObject(ipDstAddress.getIp4Address().toInt());
subObjects.add(subObj);
}
return subObjects;
}
@Override
public void removeRulesById(ApplicationId id, FlowRule... flowRules) {
// TODO
removeFlowRule(flowRules);
// TODO Auto-generated method stub
}
@Override
public void executeBatch(FlowRuleBatchOperation batch) {
Collection<FlowEntry> flowEntries = new ArrayList<>();
for (FlowRuleBatchEntry fbe : batch.getOperations()) {
Criterion criteria = fbe.target().selector().getCriterion(EXTENSION);
switch (fbe.operator()) {
case ADD:
if (criteria == null) {
processRule(fbe.target(), PcepFlowType.ADD);
flowEntries.add(new DefaultFlowEntry(fbe.target(), FlowEntryState.ADDED, 0, 0, 0));
}
break;
case REMOVE:
if (criteria == null) {
processRule(fbe.target(), PcepFlowType.REMOVE);
flowEntries.add(new DefaultFlowEntry(fbe.target(), FlowEntryState.REMOVED, 0, 0, 0));
}
break;
default:
log.error("Unknown flow operation: {}", fbe);
}
}
// TODO Auto-generated method stub
CompletedBatchOperation status = new CompletedBatchOperation(true, Collections.emptySet(), batch.deviceId());
providerService.batchOperationCompleted(batch.id(), status);
providerService.pushFlowMetrics(batch.deviceId(), flowEntries);
}
}
......
......@@ -5,7 +5,6 @@ BUNDLES = [
'//protocols/pcep/pcepio:onos-protocols-pcep-pcepio',
'//protocols/pcep/ctl:onos-protocols-pcep-ctl',
'//apps/pcep-api:onos-apps-pcep-api',
'//providers/pcep/packet:onos-providers-pcep-packet',
]
onos_app (
......
COMPILE_DEPS = [
'//lib:CORE_DEPS',
'//protocols/pcep/api:onos-protocols-pcep-api',
]
osgi_jar_with_tests (
deps = COMPILE_DEPS,
)
<!--
~ 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.7.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>
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.MacAddress;
import org.onlab.packet.TCP;
import org.onosproject.net.ConnectPoint;
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.setDestinationMACAddress(MacAddress.NONE);
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 = DeviceId.deviceId(lsrId);
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.
}
}
@Override
public void emit(OutboundPacket packet) {
// Nothing to emit
}
}
......@@ -27,6 +27,5 @@
<module>topology</module>
<module>tunnel</module>
<module>app</module>
<module>packet</module>
</modules>
</project>
\ No newline at end of file
......
COMPILE_DEPS = [
'//lib:CORE_DEPS',
'//incubator/api:onos-incubator-api',
'//protocols/ovsdb/api:onos-protocols-ovsdb-api',
'//protocols/ovsdb/rfc:onos-protocols-ovsdb-rfc',
'//apps/pcep-api:onos-apps-pcep-api',
......
......@@ -25,6 +25,10 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Deactivate;
import org.onlab.packet.IpAddress;
import org.onosproject.incubator.net.tunnel.DefaultLabelStack;
import org.onosproject.incubator.net.tunnel.LabelStack;
import org.onosproject.incubator.net.tunnel.Tunnel;
import org.onosproject.net.Path;
import org.onosproject.pcep.controller.ClientCapability;
import org.onosproject.pcep.controller.PccId;
import org.onosproject.pcep.controller.PcepClient;
......@@ -32,7 +36,6 @@ import org.onosproject.pcep.controller.PcepClientController;
import org.onosproject.pcep.controller.PcepClientListener;
import org.onosproject.pcep.controller.PcepEventListener;
import org.onosproject.pcep.controller.PcepNodeListener;
import org.onosproject.pcep.controller.PcepPacketListener;
import org.onosproject.pcep.controller.driver.PcepAgent;
import org.onosproject.pcepio.protocol.PcepError;
import org.onosproject.pcepio.protocol.PcepErrorInfo;
......@@ -41,6 +44,7 @@ import org.onosproject.pcepio.protocol.PcepErrorObject;
import org.onosproject.pcepio.protocol.PcepFactory;
import org.onosproject.pcepio.protocol.PcepMessage;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.onosproject.pcepio.types.PcepValueType;
import com.google.common.collect.Sets;
......@@ -290,14 +294,20 @@ public class PcepClientControllerAdapter implements PcepClientController {
}
@Override
public void addPacketListener(PcepPacketListener listener) {
public LabelStack computeLabelStack(Path path) {
// TODO Auto-generated method stub
return null;
}
@Override
public void removePacketListener(PcepPacketListener listener) {
public LinkedList<PcepValueType> createPcepLabelStack(DefaultLabelStack labelStack, Path path) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean allocateLocalLabel(Tunnel tunnel) {
// TODO Auto-generated method stub
return false;
}
}
......
......@@ -100,7 +100,6 @@ import org.onosproject.pcepio.protocol.PcepLspObject;
import org.onosproject.pcepio.protocol.PcepMessage;
import org.onosproject.pcepio.protocol.PcepMetricObject;
import org.onosproject.pcepio.protocol.PcepMsgPath;
import org.onosproject.pcepio.protocol.PcepNai;
import org.onosproject.pcepio.protocol.PcepReportMsg;
import org.onosproject.pcepio.protocol.PcepSrpObject;
import org.onosproject.pcepio.protocol.PcepStateReport;
......@@ -109,7 +108,6 @@ import org.onosproject.pcepio.protocol.PcepUpdateRequest;
import org.onosproject.pcepio.types.IPv4SubObject;
import org.onosproject.pcepio.types.PathSetupTypeTlv;
import org.onosproject.pcepio.types.PcepNaiIpv4Adjacency;
import org.onosproject.pcepio.types.PcepNaiIpv4NodeId;
import org.onosproject.pcepio.types.PcepValueType;
import org.onosproject.pcepio.types.SrEroSubObject;
import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
......@@ -124,7 +122,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
......@@ -280,7 +277,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
collectors.values().forEach(tsc -> tsc.adjustPollInterval(tunnelStatsPollFrequency));
log.info("New setting: tunnelStatsPollFrequency={}", tunnelStatsPollFrequency);
}
}
@Override
......@@ -318,8 +314,27 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
//TODO: tunnel which is passed doesn't have tunnelID
if (tunnel.annotations().value(PLSP_ID) != null) {
if (LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)) != WITHOUT_SIGNALLING_AND_WITHOUT_SR) {
// For CR LSPs, BGP flow provider will send update message after pushing labels.
updateTunnel(tunnel, path);
} else {
// Download labels and send update message.
// To get new tunnel ID (modified tunnel ID)
Collection<Tunnel> tunnels = tunnelService.queryTunnel(tunnel.src(), tunnel.dst());
for (Tunnel t : tunnels) {
if (t.state().equals(INIT) && t.tunnelName().equals(tunnel.tunnelName())) {
tunnel = new DefaultTunnel(tunnel.providerId(), tunnel.src(),
tunnel.dst(), tunnel.type(),
t.state(), tunnel.groupId(),
t.tunnelId(),
tunnel.tunnelName(),
tunnel.path(),
tunnel.resource(),
tunnel.annotations());
break;
}
}
if (!pcepClientController.allocateLocalLabel(tunnel)) {
log.error("Unable to allocate labels for the tunnel {}.", tunnel.toString());
}
}
return;
}
......@@ -806,13 +821,11 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
extendAnnotations);
}
TunnelDescription tunnel = new DefaultTunnelDescription(
tunnelId,
TunnelDescription tunnel = new DefaultTunnelDescription(tunnelId,
srcPoint,
dstPoint,
tunnelType,
new DefaultGroupId(
0),
new DefaultGroupId(0),
id(), name,
path,
annotations);
......@@ -904,55 +917,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
}
/**
* Creates label stack for ERO object from network resource.
*
* @param labelStack
* @param path (hop list)
* @return list of ERO subobjects
*/
private LinkedList<PcepValueType> createPcepLabelStack(DefaultLabelStack labelStack, Path path) {
checkNotNull(labelStack);
LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>();
Iterator<Link> links = path.links().iterator();
LabelResourceId label = null;
Link link = null;
PcepValueType subObj = null;
PcepNai nai = null;
Device dstNode = null;
long srcPortNo, dstPortNo;
ListIterator<LabelResourceId> labelListIterator = labelStack.labelResources().listIterator();
while (labelListIterator.hasNext()) {
label = labelListIterator.next();
link = links.next();
srcPortNo = link.src().port().toLong();
srcPortNo = ((srcPortNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? srcPortNo & SET : srcPortNo;
dstPortNo = link.dst().port().toLong();
dstPortNo = ((dstPortNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? dstPortNo & SET : dstPortNo;
nai = new PcepNaiIpv4Adjacency((int) srcPortNo, (int) dstPortNo);
subObj = new SrEroSubObject(PcepNaiIpv4Adjacency.ST_TYPE, false, false, false, true, (int) label.labelId(),
nai);
llSubObjects.add(subObj);
dstNode = deviceService.getDevice(link.dst().deviceId());
nai = new PcepNaiIpv4NodeId(Ip4Address.valueOf(dstNode.annotations().value(LSRID)).toInt());
if (!labelListIterator.hasNext()) {
log.error("Malformed label stack.");
}
label = labelListIterator.next();
subObj = new SrEroSubObject(PcepNaiIpv4NodeId.ST_TYPE, false, false, false, true, (int) label.labelId(),
nai);
llSubObjects.add(subObj);
}
return llSubObjects;
}
/**
* Creates PcInitiated lsp request list for setup tunnel.
*
* @param tunnel mpls tunnel
......@@ -967,10 +931,18 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
throws PcepParseException {
PcepValueType tlv;
LinkedList<PcepValueType> llSubObjects = null;
LspType lspType = LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE));
if (lspType == SR_WITHOUT_SIGNALLING) {
NetworkResource labelStack = tunnel.resource();
if (labelStack != null && labelStack instanceof DefaultLabelStack) {
llSubObjects = createPcepLabelStack((DefaultLabelStack) labelStack, path);
if (labelStack == null || !(labelStack instanceof DefaultLabelStack)) {
labelStack = pcepClientController.computeLabelStack(tunnel.path());
if (labelStack == null) {
log.error("Unable to create label stack.");
return null;
}
}
llSubObjects = pcepClientController.createPcepLabelStack((DefaultLabelStack) labelStack, path);
} else {
llSubObjects = createPcepPath(path);
}
......@@ -983,7 +955,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
// set PathSetupTypeTlv of SRP object
tlv = new PathSetupTypeTlv(LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)).type());
tlv = new PathSetupTypeTlv(lspType.type());
llOptionalTlv.add(tlv);
// build SRP object
......@@ -1115,7 +1087,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, DELETE);
pcepTunnelApiMapper.addToCoreTunnelRequestQueue(pcepTunnelData);
int srpId = SrpIdGenerators.create();
TunnelId tunnelId = tunnel.tunnelId();
PcepValueType tlv;
LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
......@@ -1193,14 +1164,21 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, UPDATE);
pcepTunnelApiMapper.addToCoreTunnelRequestQueue(pcepTunnelData);
int srpId = SrpIdGenerators.create();
TunnelId tunnelId = tunnel.tunnelId();
PcepValueType tlv;
int plspId = 0;
LinkedList<PcepValueType> llSubObjects = null;
LspType lspSigType = LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE));
if (lspSigType == SR_WITHOUT_SIGNALLING) {
NetworkResource labelStack = tunnel.resource();
if (labelStack != null && labelStack instanceof DefaultLabelStack) {
llSubObjects = createPcepLabelStack((DefaultLabelStack) labelStack, path);
if (labelStack == null || !(labelStack instanceof DefaultLabelStack)) {
labelStack = pcepClientController.computeLabelStack(tunnel.path());
if (labelStack == null) {
log.error("Unable to create label stack.");
return;
}
}
llSubObjects = pcepClientController.createPcepLabelStack((DefaultLabelStack) labelStack, path);
} else {
llSubObjects = createPcepPath(path);
}
......@@ -1209,7 +1187,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
LinkedList<PcepUpdateRequest> llUpdateRequestList = new LinkedList<PcepUpdateRequest>();
// set PathSetupTypeTlv of SRP object
LspType lspSigType = LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE));
tlv = new PathSetupTypeTlv(lspSigType.type());
llOptionalTlv.add(tlv);
......@@ -1285,8 +1262,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
}
}
private class InnerTunnelProvider implements PcepTunnelListener, PcepEventListener, PcepClientListener {
@Override
......@@ -1302,7 +1277,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
}
TunnelId tunnelId = getTunnelId(tunnelKey);
tunnel = buildOpticalTunnel(pcepTunnel, tunnelId);
OperationType operType = pcepTunnel.getOperationType();
......@@ -1737,7 +1711,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
private void tunnelUpdateInDelegatedCase(PccId pccId, SparseAnnotations annotations,
DefaultTunnelDescription td, ProviderId providerId, State tunnelState,
StatefulIPv4LspIdentifiersTlv ipv4LspIdentifiersTlv) {
//Wait for 2sec then query tunnel based on ingress PLSP-ID and local LSP-ID
// Wait for 2sec then query tunnel based on ingress PLSP-ID and local LSP-ID
/*
* If ONOS is not the master for that PCC then check if D flag is set, if yes wait [while
......@@ -1891,14 +1865,11 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
if (endOfSyncAction == PcepLspSyncAction.UNSTABLE) {
// Send PCInit msg again after global reoptimization.
tunnelUpdated(td, UNSTABLE);
// To remove the old tunnel from store whose PLSPID is not
// recognized by ingress PCC.
// To remove the old tunnel from store whose PLSPID is not recognized by ingress PCC.
tunnelRemoved(td);
} else if (endOfSyncAction == REMOVE) {
tunnelRemoved(td);
}
......
......@@ -24,13 +24,16 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Deactivate;
import org.onosproject.incubator.net.tunnel.DefaultLabelStack;
import org.onosproject.incubator.net.tunnel.LabelStack;
import org.onosproject.incubator.net.tunnel.Tunnel;
import org.onosproject.net.Path;
import org.onosproject.pcep.controller.PccId;
import org.onosproject.pcep.controller.PcepClient;
import org.onosproject.pcep.controller.PcepClientController;
import org.onosproject.pcep.controller.PcepClientListener;
import org.onosproject.pcep.controller.PcepEventListener;
import org.onosproject.pcep.controller.PcepNodeListener;
import org.onosproject.pcep.controller.PcepPacketListener;
import org.onosproject.pcep.controller.driver.PcepAgent;
import org.onosproject.pcepio.protocol.PcepError;
import org.onosproject.pcepio.protocol.PcepErrorInfo;
......@@ -39,6 +42,7 @@ import org.onosproject.pcepio.protocol.PcepErrorObject;
import org.onosproject.pcepio.protocol.PcepFactory;
import org.onosproject.pcepio.protocol.PcepMessage;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.onosproject.pcepio.types.PcepValueType;
import com.google.common.collect.Sets;
......@@ -58,7 +62,6 @@ public class PcepClientControllerAdapter implements PcepClientController {
protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet();
public Set<PcepNodeListener> pcepNodeListener = Sets.newHashSet();
protected Set<PcepPacketListener> pcepPacketListener = Sets.newHashSet();
@Activate
public void activate() {
......@@ -118,16 +121,6 @@ public class PcepClientControllerAdapter implements PcepClientController {
}
@Override
public void addPacketListener(PcepPacketListener listener) {
pcepPacketListener.add(listener);
}
@Override
public void removePacketListener(PcepPacketListener listener) {
pcepPacketListener.remove(listener);
}
@Override
public void writeMessage(PccId pccId, PcepMessage msg) {
this.getClient(pccId).sendMessage(msg);
}
......@@ -292,4 +285,22 @@ public class PcepClientControllerAdapter implements PcepClientController {
return false;
}
}
@Override
public LabelStack computeLabelStack(Path path) {
// TODO Auto-generated method stub
return null;
}
@Override
public LinkedList<PcepValueType> createPcepLabelStack(DefaultLabelStack labelStack, Path path) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean allocateLocalLabel(Tunnel tunnel) {
// TODO Auto-generated method stub
return false;
}
}
......