Priyanka B
Committed by Gerrit Code Review

[ONOS] SR resilency, CR resilency and delete problem , old tunnels not deleting issue

Change-Id: Ib4b9732c28a1f87a8a76347a5936593b1b5bf72a
......@@ -325,7 +325,7 @@ public final class BasicPceccHandler {
}
// Install a rule for pushing local labels to the device which is specific to path.
private void installLocalLabelRule(DeviceId deviceId, LabelResourceId labelId,
private synchronized void installLocalLabelRule(DeviceId deviceId, LabelResourceId labelId,
PortNumber portNum, TunnelId tunnelId,
Boolean isBos, Long labelType,
Objective.Operation type) {
......
......@@ -31,7 +31,6 @@ 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;
......@@ -110,14 +109,14 @@ import org.slf4j.LoggerFactory;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS;
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;
......@@ -621,6 +620,12 @@ 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());
}
......@@ -1148,6 +1153,22 @@ public class PceManager implements PceService {
}
}
//In CR case, release labels when new tunnel for it is updated.
if (lspType == WITHOUT_SIGNALLING_AND_WITHOUT_SR && tunnel.state() == ACTIVE
&& mastershipService.getLocalRole(tunnel.path().src().deviceId()) == MastershipRole.MASTER) {
Collection<Tunnel> tunnels = tunnelService.queryTunnel(tunnel.src(), tunnel.dst());
for (Tunnel t : tunnels) {
if (tunnel.annotations().value(PLSP_ID).equals(t.annotations().value(PLSP_ID))
&& !tunnel.annotations().value(LOCAL_LSP_ID)
.equals(t.annotations().value(LOCAL_LSP_ID))) {
// Release basic PCECC labels.
crHandler.releaseLabel(t);
break;
}
}
}
if (tunnel.state() == UNSTABLE) {
/*
* During LSP DB sync if PCC doesn't report LSP which was PCE initiated, it's state is turned into
......@@ -1183,23 +1204,16 @@ public class PceManager implements PceService {
if (lspType != WITH_SIGNALLING) {
localLspIdFreeList.add(Short.valueOf(tunnel.annotations().value(LOCAL_LSP_ID)));
}
// If not zero bandwidth, and delegated (initiated LSPs will also be delegated).
if (bwConstraintValue != 0) {
releaseBandwidth(event.subject());
// Release basic PCECC labels.
if (lspType == WITHOUT_SIGNALLING_AND_WITHOUT_SR) {
// Delete stored tunnel consumer id from PCE store (while still retaining label list.)
PceccTunnelInfo pceccTunnelInfo = pceStore.getTunnelInfo(tunnel.tunnelId());
pceccTunnelInfo.tunnelConsumerId(null);
if (mastershipService.getLocalRole(tunnel.path().src().deviceId()) == MastershipRole.MASTER) {
crHandler.releaseLabel(tunnel);
}
} else {
pceStore.removeTunnelInfo(tunnel.tunnelId());
}
if (Double.parseDouble(tunnel.annotations().value(BANDWIDTH)) != 0.0
&& mastershipService.getLocalRole(tunnel.path().src().deviceId()) == MastershipRole.MASTER) {
releaseBandwidth(tunnel);
}
if (pceStore.getTunnelInfo(tunnel.tunnelId()) != null) {
pceStore.removeTunnelInfo(tunnel.tunnelId());
}
break;
default:
......
......@@ -641,11 +641,14 @@ public class PceManagerTest {
build4RouterTopo(false, false, false, false, 5);
List<Constraint> constraints = new LinkedList<Constraint>();
CostConstraint costConstraint = new CostConstraint(TE_COST);
BandwidthConstraint bwConst = new BandwidthConstraint(Bandwidth.bps(3));
constraints.add(bwConst);
constraints.add(costConstraint);
pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
assertThat(tunnels.size(), is(1));
boolean result;
for (Tunnel tunnel : tunnels) {
......
......@@ -63,8 +63,6 @@ import org.onosproject.bgpio.types.attr.BgpLinkAttrTeDefaultMetric;
import org.onosproject.core.CoreService;
import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
import org.onosproject.incubator.net.resource.label.LabelResourceId;
import org.onosproject.mastership.MastershipEvent;
import org.onosproject.mastership.MastershipListener;
import org.onosproject.mastership.MastershipService;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.ConnectPoint;
......@@ -79,6 +77,8 @@ import org.onosproject.net.config.basics.BandwidthCapacity;
import org.onosproject.net.device.DefaultDeviceDescription;
import org.onosproject.net.device.DefaultPortDescription;
import org.onosproject.net.device.DeviceDescription;
import org.onosproject.net.device.DeviceEvent;
import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.device.DeviceProvider;
import org.onosproject.net.device.DeviceProviderRegistry;
import org.onosproject.net.device.DeviceProviderService;
......@@ -140,7 +140,7 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi
private DeviceProviderService deviceProviderService;
private LinkProviderService linkProviderService;
private InternalMastershipListener masterListener = new InternalMastershipListener();
private DeviceListener deviceListener = new InternalDeviceListener();
private InternalBgpProvider listener = new InternalBgpProvider();
private static final String UNKNOWN = "unknown";
public static final long IDENTIFIER_SET = 0x100000000L;
......@@ -169,7 +169,7 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi
deviceProviderService = deviceProviderRegistry.register(this);
linkProviderService = linkProviderRegistry.register(this);
controller.addListener(listener);
mastershipService.addListener(masterListener);
deviceService.addListener(deviceListener);
controller.addLinkListener(listener);
}
......@@ -182,25 +182,28 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi
linkProviderService = null;
controller.removeListener(listener);
controller.removeLinkListener(listener);
mastershipService.removeListener(masterListener);
deviceService.removeListener(deviceListener);
}
private class InternalMastershipListener implements MastershipListener {
private class InternalDeviceListener implements DeviceListener {
@Override
public void event(MastershipEvent event) {
if (event.type() == MastershipEvent.Type.MASTER_CHANGED) {
if (mastershipService.getMasterFor(event.subject()) != null) {
//Only for L3 device create label pool for that device
Device device = deviceService.getDevice(event.subject());
if (device == null) {
log.debug("Device {} doesn't exist", event.subject());
return;
public void event(DeviceEvent event) {
Device device = event.subject();
switch (event.type()) {
case DEVICE_ADDED:
if (!mastershipService.isLocalMaster(device.id())) {
break;
}
//Reserve device label pool for L3 devices
// Reserve device label pool for L3 devices
if (device.annotations().value(LSRID) != null) {
createDevicePool(event.subject());
createDevicePool(device.id());
}
}
break;
default:
break;
}
}
}
......@@ -444,7 +447,6 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi
@Override
public void deleteLink(BgpLinkLsNlriVer4 linkNlri) throws BgpParseException {
log.debug("Delete link {}", linkNlri.toString());
if (linkProviderService == null) {
return;
}
......@@ -461,6 +463,10 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi
}
linkProviderService.linkVanished(linkDes);
linkDes = new DefaultLinkDescription(linkDes.dst(), linkDes.src(), Link.Type.DIRECT,
false, linkDes.annotations());
linkProviderService.linkVanished(linkDes);
}
}
......
......@@ -53,10 +53,7 @@ import org.onosproject.bgpio.types.LinkStateAttributes;
import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
import org.onosproject.incubator.net.resource.label.LabelResourceId;
import org.onosproject.incubator.net.resource.label.LabelResourcePool;
import org.onosproject.mastership.MastershipEvent;
import org.onosproject.mastership.MastershipListener;
import org.onosproject.mastership.MastershipServiceAdapter;
import org.onosproject.mastership.MastershipEvent.Type;
import org.onosproject.net.link.LinkServiceAdapter;
import org.onosproject.bgpio.types.LinkLocalRemoteIdentifiersTlv;
import org.onosproject.bgpio.types.RouteDistinguisher;
......@@ -68,8 +65,8 @@ import org.onosproject.bgpio.types.attr.BgpLinkAttrMaxLinkBandwidth;
import org.onosproject.bgpio.types.attr.BgpLinkAttrTeDefaultMetric;
import org.onosproject.bgpio.util.Constants;
import org.onosproject.cluster.NodeId;
import org.onosproject.cluster.RoleInfo;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultDevice;
import org.onosproject.net.DefaultLink;
import org.onosproject.net.Device;
......@@ -82,6 +79,8 @@ import org.onosproject.net.config.ConfigApplyDelegate;
import org.onosproject.net.config.ConfigFactory;
import org.onosproject.net.config.NetworkConfigRegistryAdapter;
import org.onosproject.net.device.DeviceDescription;
import org.onosproject.net.device.DeviceEvent;
import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.device.DeviceProvider;
import org.onosproject.net.device.DeviceProviderRegistry;
import org.onosproject.net.device.DeviceProviderService;
......@@ -122,7 +121,7 @@ public class BgpTopologyProviderTest {
private MockNetConfigRegistryAdapter networkConfigService = new MockNetConfigRegistryAdapter();
private MockLabelResourceService labelResourceAdminService = new MockLabelResourceService();
private Map<DeviceId, Device> deviceMap = new HashMap<>();
private MastershipListener listener;
private DeviceListener listener;
@Before
public void startUp() throws TestUtilsException {
......@@ -134,7 +133,7 @@ public class BgpTopologyProviderTest {
provider.labelResourceAdminService = labelResourceAdminService;
provider.mastershipService = mastershipService;
provider.networkConfigService = networkConfigService;
listener = TestUtils.getField(provider, "masterListener");
listener = TestUtils.getField(provider, "deviceListener");
provider.activate();
assertThat("device provider should be registered", not(nodeRegistry.provider));
assertThat("link provider should be registered", not(linkRegistry.linkProvider));
......@@ -887,10 +886,14 @@ public class BgpTopologyProviderTest {
l.addNode(nodeNlri, details);
assertThat(nodeRegistry.connected.size(), is(1));
}
DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
MastershipEvent event = new MastershipEvent(Type.MASTER_CHANGED, nodeRegistry.connected.iterator().next(),
new RoleInfo(NodeId.nodeId("Node1"), new LinkedList<>()));
newBuilder.set("lsrId", "1.1.1.1");
Device device = new DefaultDevice(BgpTopologyProviderTest.providerId, nodeRegistry.connected.iterator().next(),
Device.Type.ROUTER, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, new ChassisId(), newBuilder.build());
DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device);
listener.event(event);
assertThat(labelResourceAdminService.resourcePool.keySet().size(), is(1));
}
......@@ -926,9 +929,16 @@ public class BgpTopologyProviderTest {
for (BgpNodeListener l : controller.nodeListener) {
l.addNode(nodeNlri, details);
assertThat(nodeRegistry.connected.size(), is(1));
// Check label resource reserved for that device
MastershipEvent event = new MastershipEvent(Type.MASTER_CHANGED, nodeRegistry.connected.iterator().next(),
new RoleInfo(NodeId.nodeId("Node1"), new LinkedList<>()));
DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
newBuilder.set("lsrId", "1.1.1.1");
Device device = new DefaultDevice(BgpTopologyProviderTest.providerId,
nodeRegistry.connected.iterator().next(), Device.Type.ROUTER, UNKNOWN,
UNKNOWN, UNKNOWN, UNKNOWN, new ChassisId(), newBuilder.build());
DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device);
listener.event(event);
assertThat(labelResourceAdminService.resourcePool.keySet().size(), is(1));
......@@ -988,8 +998,15 @@ public class BgpTopologyProviderTest {
l.addNode(nodeNlri, details);
assertThat(nodeRegistry.connected.size(), is(1));
//Check label resource reserved for that device
MastershipEvent event = new MastershipEvent(Type.MASTER_CHANGED, nodeRegistry.connected.iterator().next(),
new RoleInfo(NodeId.nodeId("Node1"), new LinkedList<>()));
DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
newBuilder.set("lsrId", "1.1.1.1");
Device device = new DefaultDevice(BgpTopologyProviderTest.providerId,
nodeRegistry.connected.iterator().next(), Device.Type.ROUTER,
UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, new ChassisId(), newBuilder.build());
DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device);
listener.event(event);
assertThat(labelResourceAdminService.resourcePool.keySet().size(), is(1));
l.addNode(remNodeNlri, details);
......
......@@ -573,18 +573,22 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
return tunnelId;
}
private void tunnelUpdated(Tunnel tunnel, Path path) {
handleTunnelUpdate(tunnel, path);
private void tunnelUpdated(Tunnel tunnel, Path path, State tunnelState) {
handleTunnelUpdate(tunnel, path, tunnelState);
}
//Handles tunnel updated using tunnel admin service[specially to update annotations].
private void handleTunnelUpdate(Tunnel tunnel, Path path) {
private void handleTunnelUpdate(Tunnel tunnel, Path path, State tunnelState) {
if (tunnel.type() == MPLS) {
pcepTunnelApiMapper.removeFromCoreTunnelRequestQueue(tunnel.tunnelId());
tunnelAdminService.updateTunnel(tunnel, path);
TunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(), tunnel.src(), tunnel.dst(),
tunnel.type(), tunnel.groupId(), tunnel.providerId(),
tunnel.tunnelName(), path, tunnel.resource(),
(SparseAnnotations) tunnel.annotations());
service.tunnelUpdated(td, tunnelState);
return;
}
......@@ -1451,7 +1455,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
}
private SparseAnnotations getAnnotations(PcepLspObject lspObj, StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv,
float bandwidth, LspType lspType, String costType) {
float bandwidth, LspType lspType, String costType, boolean isPceInit) {
Builder builder = DefaultAnnotations.builder();
......@@ -1463,8 +1467,13 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
builder.set(COST_TYPE, costType);
}
if (isPceInit) {
builder.set(PCE_INIT, String.valueOf(isPceInit));
}
SparseAnnotations annotations = builder
.set(BANDWIDTH, (new Float(bandwidth)).toString()).set(LSP_SIG_TYPE, lspType.name())
.set(BANDWIDTH, (new Float(bandwidth)).toString())
.set(LSP_SIG_TYPE, lspType.name())
.set(PCC_TUNNEL_ID, String.valueOf(ipv4LspIdenTlv.getTunnelId()))
.set(PLSP_ID, String.valueOf(lspObj.getPlspId()))
.set(LOCAL_LSP_ID, String.valueOf(ipv4LspIdenTlv.getLspId()))
......@@ -1530,6 +1539,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
bandwidth = attributes.getBandwidthObject().getBandwidth();
}
}
PcepLspObject lspObj = stateRpt.getLspObject();
List<Object> eroSubObjList = buildPathFromEroObj(eroObj, providerId);
List<Link> links = new ArrayList<>();
List<LabelResourceId> labels = new ArrayList<>();
......@@ -1540,21 +1550,20 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
labels.add(LabelResourceId.labelResourceId(((Integer) linkOrLabel).longValue()));
}
}
if (links.isEmpty()) {
Path path = null;
if (!links.isEmpty()) {
path = new DefaultPath(providerId, links, cost, EMPTY);
} else if (!lspObj.getRFlag()) {
return;
}
Path path = new DefaultPath(providerId, links, cost, EMPTY);
NetworkResource labelStack = new DefaultLabelStack(labels);
// To carry PST TLV, SRP object can be present with value 0 even when PCRpt is not in response to any action
// from PCE.
PcepSrpObject srpObj = stateRpt.getSrpObject();
LspType lspType = getLspType(srpObj);
PcepLspObject lspObj = stateRpt.getLspObject();
ListIterator<PcepValueType> listTlvIterator = lspObj.getOptionalTlv().listIterator();
StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv = null;
SymbolicPathNameTlv pathNameTlv = null;
while (listTlvIterator.hasNext()) {
PcepValueType tlv = listTlvIterator.next();
switch (tlv.getType()) {
......@@ -1629,12 +1638,10 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
log.error("Ingress deviceId not found");
return;
}
annotations = getAnnotations(lspObj, ipv4LspIdenTlv, bandwidth, lspType, costType);
annotations = getAnnotations(lspObj, ipv4LspIdenTlv, bandwidth, lspType, costType, lspObj.getCFlag());
td = new DefaultTunnelDescription(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, new DefaultGroupId(
0), providerId, TunnelName.tunnelName(new String(pathNameTlv.getValue())), path, labelStack,
annotations);
// Do not support PCC initiated LSP after LSP DB sync is completed.
if (!lspObj.getSFlag() && !lspObj.getCFlag()) {
log.error("Received PCC initiated LSP while not in sync.");
......@@ -1671,43 +1678,58 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
} else if (!mastershipService.isLocalMaster(deviceId) && lspObj.getDFlag()) {
//Start timer then update the tunnel with D flag
tunnelUpdateInDelegatedCase(pccId, annotations, td, providerId);
tunnelUpdateInDelegatedCase(pccId, annotations, td, providerId, tunnelState, ipv4LspIdenTlv);
}
return;
}
//delegated owner will update can be a master or non-master
if (lspObj.getDFlag()) {
if (tunnel.annotations().value(BANDWIDTH) != null) {
bandwidth = Float.parseFloat(tunnel.annotations().value(BANDWIDTH));
}
annotations = getAnnotations(lspObj, ipv4LspIdenTlv,
bandwidth, lspType,
tunnel.annotations().value(COST_TYPE));
td = new DefaultTunnelDescription(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, new DefaultGroupId(
0), providerId, TunnelName.tunnelName(new String(pathNameTlv.getValue())),
tunnel.path(), labelStack, annotations);
tunnelUpdateInDelegatedCase(pccId, annotations, td, providerId);
if (lspObj.getDFlag() && !lspObj.getRFlag()) {
tunnelUpdateForDelegatedLsp(tunnel, lspObj,
lspType, tunnelState, pccId, labelStack, ipv4LspIdenTlv);
return;
}
removeOrUpdatetunnel(tunnel, pccId, lspObj, providerId, tunnelState);
return;
removeOrUpdatetunnel(tunnel, lspObj, providerId, tunnelState, ipv4LspIdenTlv);
}
private void removeOrUpdatetunnel(Tunnel tunnel, PccId pccId, PcepLspObject lspObj, ProviderId providerId,
State tunnelState) {
private void tunnelUpdateForDelegatedLsp(Tunnel tunnel, PcepLspObject lspObj,
LspType lspType, State tunnelState, PccId pccId,
NetworkResource labelStack,
StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv) {
SparseAnnotations annotations = null;
Float bandwidth = 0.0f;
DefaultTunnelDescription td;
if (tunnel.annotations().value(BANDWIDTH) != null) {
bandwidth = Float.parseFloat(tunnel.annotations().value(BANDWIDTH));
}
boolean isPceInit = tunnel.annotations().value(PCE_INIT) == null ? false :
Boolean.valueOf((tunnel.annotations().value(PCE_INIT))).booleanValue();
annotations = getAnnotations(lspObj, ipv4LspIdenTlv,
bandwidth, lspType,
tunnel.annotations().value(COST_TYPE), isPceInit);
td = new DefaultTunnelDescription(null, tunnel.src(), tunnel.dst(), MPLS, new DefaultGroupId(
0), tunnel.providerId(), tunnel.tunnelName(),
tunnel.path(), labelStack, annotations);
tunnelUpdateInDelegatedCase(pccId, annotations, td, tunnel.providerId(), tunnelState, ipv4LspIdenTlv);
}
private void removeOrUpdatetunnel(Tunnel tunnel, PcepLspObject lspObj, ProviderId providerId,
State tunnelState, StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv) {
DefaultTunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(), tunnel.src(), tunnel.dst(),
tunnel.type(), tunnel.groupId(), providerId, tunnel.tunnelName(), tunnel.path(),
(SparseAnnotations) tunnel.annotations());
if (lspObj.getRFlag()) {
tunnelRemoved(td);
} else {
PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, tunnel.path(), LSP_STATE_RPT);
pcepTunnelData.setStatefulIpv4IndentifierTlv(ipv4LspIdenTlv);
pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
tunnelUpdated(td, tunnelState);
}
}
private void tunnelUpdateInDelegatedCase(PccId pccId, SparseAnnotations annotations,
DefaultTunnelDescription td, ProviderId providerId) {
DefaultTunnelDescription td, ProviderId providerId, State tunnelState,
StatefulIPv4LspIdentifiersTlv ipv4LspIdentifiersTlv) {
//Wait for 2sec then query tunnel based on ingress PLSP-ID and local LSP-ID
/*
......@@ -1718,7 +1740,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
// Thread is started after 2 seconds first time later periodically after 2 seconds to update the tunnel
executor.scheduleAtFixedRate(new UpdateDelegation(td, providerId, annotations, pccId,
executor), DELAY, DELAY, TimeUnit.SECONDS);
executor, tunnelState, ipv4LspIdentifiersTlv), DELAY, DELAY, TimeUnit.SECONDS);
}
/**
......@@ -1823,7 +1845,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
// the other sub objects are not required
}
}
return subObjList;
}
......@@ -1881,7 +1902,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
return service.tunnelQueryById(tunnelId);
}
private DeviceId getDevice(PccId pccId) {
// Get lsrId of the PCEP client from the PCC ID. Session info is based on lsrID.
IpAddress lsrId = pccId.ipAddress();
......@@ -1908,6 +1928,8 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
SparseAnnotations annotations;
PccId pccId;
ScheduledExecutorService executor;
State tunnelState;
StatefulIPv4LspIdentifiersTlv ipv4LspIdentifiersTlv;
/**
* Creates an instance of UpdateDelegation.
......@@ -1919,12 +1941,15 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
* @param executor service of delegated owner
*/
public UpdateDelegation(DefaultTunnelDescription td, ProviderId providerId, SparseAnnotations annotations,
PccId pccId, ScheduledExecutorService executor) {
PccId pccId, ScheduledExecutorService executor, State tunnelState,
StatefulIPv4LspIdentifiersTlv ipv4LspIdentifiersTlv) {
this.td = td;
this.providerId = providerId;
this.annotations = annotations;
this.pccId = pccId;
this.executor = executor;
this.tunnelState = tunnelState;
this.ipv4LspIdentifiersTlv = ipv4LspIdentifiersTlv;
}
//Temporary using annotations later will use projection/network config service
......@@ -1950,7 +1975,11 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
if (tempTunnelId != null) {
Tunnel tunnel = new DefaultTunnel(providerId, td.src(), td.dst(), MPLS, new DefaultGroupId(0),
tempTunnelId, td.tunnelName(), td.path(), annotations);
tunnelUpdated(tunnel, td.path());
PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, tunnel.path(), LSP_STATE_RPT);
pcepTunnelData.setStatefulIpv4IndentifierTlv(ipv4LspIdentifiersTlv);
pcepTunnelData.setLspDFlag(Boolean.valueOf(tunnel.annotations().value(DELEGATE)));
pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
tunnelUpdated(tunnel, td.path(), tunnelState);
executor.shutdown();
try {
executor.awaitTermination(WAIT_TIME, TimeUnit.SECONDS);
......
......@@ -36,6 +36,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
......@@ -88,6 +89,7 @@ import org.onosproject.pcep.controller.ClientCapability;
import org.onosproject.pcep.controller.LspKey;
import org.onosproject.pcep.controller.PccId;
import com.esotericsoftware.minlog.Log;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet;
......@@ -223,6 +225,7 @@ public class PcepTunnelAddedTest {
tunnel.path(),
tunnel.resource(),
tunnel.annotations());
Log.info("tunnel.annotations().toString() " + tunnel.annotations().toString());
tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel);
return id;
}
......@@ -237,6 +240,18 @@ public class PcepTunnelAddedTest {
@Override
public void tunnelUpdated(TunnelDescription tunnel, State state) {
TunnelId id = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
Tunnel storedTunnel = new DefaultTunnel(ProviderId.NONE,
tunnel.src(), tunnel.dst(),
tunnel.type(),
tunnel.groupId(),
id,
tunnel.tunnelName(),
tunnel.path(),
tunnel.resource(),
tunnel.annotations());
tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel);
Log.info("tunnelService.tunnelIdAsKeyStore ++ " + tunnelService.tunnelIdAsKeyStore.toString());
}
@Override
......@@ -254,6 +269,7 @@ public class PcepTunnelAddedTest {
public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) {
TunnelId tunnelId = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
tunnelIdAsKeyStore.put(tunnelId, tunnel);
Log.info("tunnelIdAsKeyStore insetup :: " + tunnelIdAsKeyStore.toString());
return tunnelId;
}
......@@ -592,8 +608,11 @@ public class PcepTunnelAddedTest {
controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
TimeUnit.MILLISECONDS.sleep(4000);
assertThat(registry.tunnelIdCounter, is((long) 1));
assertThat(tunnelService.tunnelIdAsKeyStore.values().iterator().next().annotations().value(DELEGATE),
assertThat(registry.tunnelIdCounter, is((long) 2));
Iterator<Tunnel> iterator = tunnelService.tunnelIdAsKeyStore.values().iterator();
iterator.next();
assertThat(iterator.next().annotations().value(DELEGATE),
is("true"));
}
......