Avantika-Huawei
Committed by Gerrit Code Review

[ONOS-4707] GoldenEye - SR-TE LSPs setup issues

Change-Id: I96efb496577d4ccfbbb8f9957703b4a4da126d8a
......@@ -406,15 +406,6 @@ public final class PceccSrTeBeHandler {
DeviceId deviceId = null;
for (Iterator<Link> iterator = linkList.iterator(); iterator.hasNext();) {
link = iterator.next();
// Add source device label now
deviceId = link.src().deviceId();
nodeLabelId = pceStore.getGlobalNodeLabel(deviceId);
if (nodeLabelId == null) {
log.error("Unable to find node label for a device id {} in store.", deviceId.toString());
return null;
}
labelStack.add(nodeLabelId);
// Add adjacency label for this link
adjLabelId = pceStore.getAdjLabel(link);
if (adjLabelId == null) {
......@@ -422,11 +413,7 @@ public final class PceccSrTeBeHandler {
return null;
}
labelStack.add(adjLabelId);
}
// This is the last link in path
// Add destination device label now.
if (link != null) {
deviceId = link.dst().deviceId();
nodeLabelId = pceStore.getGlobalNodeLabel(deviceId);
if (nodeLabelId == null) {
......
......@@ -417,11 +417,8 @@ public class PceccSrTeBeHandlerTest {
// Compute label stack
LabelStack labelStack = srTeHandler.computeLabelStack(path1);
// check node-label of D1.deviceId()
List<LabelResourceId> labelList = labelStack.labelResources();
Iterator<LabelResourceId> iterator = labelList.iterator();
labelId = iterator.next();
assertThat(labelId, is(LabelResourceId.labelResourceId(4097)));
// check adjacency label of D1.deviceId()
labelId = iterator.next();
......
......@@ -59,6 +59,14 @@ public class PcepNaiIpv4Adjacency implements PcepNai {
return ST_TYPE;
}
public int getLocalIpv4Addr() {
return localIpv4Addr;
}
public int getRemoteIpv4Addr() {
return remoteIpv4Addr;
}
@Override
public int write(ChannelBuffer bb) {
int iLenStartIndex = bb.writerIndex();
......
......@@ -84,7 +84,7 @@ public class SrEroSubObject implements PcepValueType {
*/
protected static final Logger log = LoggerFactory.getLogger(SrEroSubObject.class);
public static final short TYPE = 0x60; //TODO : type to be defined
public static final short TYPE = 0x24; //TODO : type to be defined
public static final short LENGTH = 12;
public static final short VALUE_LENGTH = 10;
public static final int SET = 1;
......@@ -243,9 +243,10 @@ public class SrEroSubObject implements PcepValueType {
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeByte(TYPE);
// Store the position of object length
int objectLenIndex = c.writerIndex();
c.writeByte(0);
short temp = 0;
if (bMFlag) {
......@@ -264,13 +265,14 @@ public class SrEroSubObject implements PcepValueType {
temp = (short) (temp | tempST);
c.writeShort(temp);
if (bMFlag) {
int tempSid = (int) sid << 12;
int tempSid = sid << 12;
c.writeInt(tempSid);
} else {
c.writeInt(sid);
}
nai.write(c);
c.setByte(objectLenIndex, (c.writerIndex() - iLenStartIndex));
return c.writerIndex() - iLenStartIndex;
}
......
......@@ -28,6 +28,8 @@ import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.core.DefaultGroupId;
import org.onosproject.incubator.net.resource.label.LabelResourceId;
import org.onosproject.incubator.net.tunnel.DefaultLabelStack;
import org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint;
import org.onosproject.incubator.net.tunnel.DefaultTunnel;
import org.onosproject.incubator.net.tunnel.DefaultTunnelDescription;
......@@ -59,6 +61,7 @@ import org.onosproject.net.DeviceId;
import org.onosproject.net.ElementId;
import org.onosproject.net.IpElementId;
import org.onosproject.net.Link;
import org.onosproject.net.NetworkResource;
import org.onosproject.net.Path;
import org.onosproject.net.PortNumber;
import org.onosproject.net.SparseAnnotations;
......@@ -94,6 +97,7 @@ 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;
......@@ -101,7 +105,10 @@ import org.onosproject.pcepio.protocol.PcepUpdateMsg;
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;
import org.onosproject.pcepio.types.SymbolicPathNameTlv;
import org.osgi.service.component.ComponentContext;
......@@ -114,6 +121,7 @@ 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;
......@@ -432,8 +440,13 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
return;
}
// If delegation flag is set then only send update message[means delegated PCE can send update msg for that
// LSP].If annotation is null D flag is not set else it is set.
//PCInitiate tunnels are always have D flag set, else check for tunnels who are delegated via LspKey
if (pc.capability().statefulPceCapability()) {
if (tunnel.annotations().value(PCE_INIT) != null && tunnel.annotations().value(PCE_INIT).equals("true")) {
pcepUpdateTunnel(tunnel, path, pc);
} else {
// If delegation flag is set then only send update message[means delegated PCE can send update msg for
// that LSP. If annotation is null D flag is not set else it is set.
Short localLspId = 0;
for (Tunnel t : tunnels) {
if (!t.tunnelId().equals(tunnel.tunnelId()) && t.tunnelName().equals(tunnel.tunnelName())) {
......@@ -446,17 +459,14 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
return;
}
//PCInitiate tunnels are always have D flag set, else check for tunnels who are delegated via LspKey
if (pc.capability().statefulPceCapability()) {
if (tunnel.annotations().value(PCE_INIT) != null && tunnel.annotations().value(PCE_INIT).equals("true")) {
pcepUpdateTunnel(tunnel, path, pc);
} else if (pc.delegationInfo(
new LspKey(Integer.valueOf(tunnel.annotations().value(PLSP_ID)),
if (pc.delegationInfo(new LspKey(Integer.valueOf(tunnel.annotations().value(PLSP_ID)),
localLspId.shortValue())) != null) {
pcepUpdateTunnel(tunnel, path, pc);
}
}
}
}
@Override
public void updateTunnel(ElementId srcElement, Tunnel tunnel, Path path) {
......@@ -844,7 +854,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
* Creates list of hops for ERO object from Path.
*
* @param path network path
* @return list of ipv4 subobjects
* @return list of ERO subobjects
*/
private LinkedList<PcepValueType> createPcepPath(Path path) {
LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>();
......@@ -879,6 +889,55 @@ 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
......@@ -892,7 +951,14 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
PcepClient pc, int srpId)
throws PcepParseException {
PcepValueType tlv;
LinkedList<PcepValueType> llSubObjects = createPcepPath(path);
LinkedList<PcepValueType> llSubObjects = null;
NetworkResource labelStack = tunnel.resource();
if (labelStack != null && labelStack instanceof DefaultLabelStack) {
llSubObjects = createPcepLabelStack((DefaultLabelStack) labelStack, path);
} else {
llSubObjects = createPcepPath(path);
}
if (llSubObjects == null || llSubObjects.size() == 0) {
log.error("There is no link information to create tunnel");
......@@ -931,8 +997,8 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
llOptionalTlv.add(tlv);
//build LSP object
PcepLspObject lspobj = pc.factory().buildLspObject().setAFlag(true).setOFlag((byte) 0).setPlspId(0)
.setOptionalTlv(llOptionalTlv).build();
PcepLspObject lspobj = pc.factory().buildLspObject().setAFlag(true).setDFlag(true).setOFlag((byte) 0)
.setPlspId(0).setOptionalTlv(llOptionalTlv).build();
//build ENDPOINTS object
PcepEndPointsObject endpointsobj = pc.factory().buildEndPointsObject()
......@@ -1108,7 +1174,14 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
PcepValueType tlv;
int plspId = 0;
LinkedList<PcepValueType> llSubObjects = createPcepPath(path);
LinkedList<PcepValueType> llSubObjects = null;
NetworkResource labelStack = tunnel.resource();
if (labelStack != null && labelStack instanceof DefaultLabelStack) {
llSubObjects = createPcepLabelStack((DefaultLabelStack) labelStack, path);
} else {
llSubObjects = createPcepPath(path);
}
LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
LinkedList<PcepUpdateRequest> llUpdateRequestList = new LinkedList<PcepUpdateRequest>();
......@@ -1318,7 +1391,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
DefaultTunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(), tunnel.src(),
tunnel.dst(), tunnel.type(), tunnel.groupId(),
providerId, tunnel.tunnelName(), path,
annotations);
tunnel.resource(), annotations);
if (CREATE == pcepTunnelData.requestType()) {
pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
......@@ -1344,7 +1417,8 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
// though there are no labels to download for SR-TE.
if ((pcepLspStatus == PcepLspStatus.GOING_UP)
&& (LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)) == SR_WITHOUT_SIGNALLING)) {
updateTunnel(tunnel, tunnel.path());
// Query again to get latest tunnel updated with protocol values from PCRpt msg.
updateTunnel(service.tunnelQueryById(tunnel.tunnelId()), tunnel.path());
}
}
......@@ -1380,12 +1454,10 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
while (listIterator.hasNext()) {
PcepValueType tlv = listIterator.next();
switch (tlv.getType()) {
case PathSetupTypeTlv.TYPE:
lspType = LspType.values()[Integer.valueOf(((PathSetupTypeTlv) tlv).getPst())];
break;
default:
break;
}
......@@ -1417,7 +1489,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
} else if (metricObj.getBType() == TE_METRIC) {
costType = "TE_COST";
}
if (costType != null) {
cost = metricObj.getMetricVal();
log.debug("Path cost {}", cost);
......@@ -1427,7 +1498,19 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
}
}
Path path = buildPathFromEroObj(eroObj, providerId, cost);
List<Object> eroSubObjList = buildPathFromEroObj(eroObj, providerId);
List<Link> links = new ArrayList<>();
List<LabelResourceId> labels = new ArrayList<>();
for (Object linkOrLabel : eroSubObjList) {
if (linkOrLabel instanceof Link) {
links.add((Link) linkOrLabel);
} else if (linkOrLabel instanceof Integer) {
labels.add(LabelResourceId.labelResourceId(((Integer) linkOrLabel).longValue()));
}
}
Path path = new DefaultPath(providerId, links, cost, EMPTY);
NetworkResource labelStack = new DefaultLabelStack(labels);
float bandwidth = 0;
if (msgPath.getBandwidthObject() != null) {
......@@ -1452,11 +1535,9 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
case StatefulIPv4LspIdentifiersTlv.TYPE:
ipv4LspIdenTlv = (StatefulIPv4LspIdentifiersTlv) tlv;
break;
case SymbolicPathNameTlv.TYPE:
pathNameTlv = (SymbolicPathNameTlv) tlv;
break;
default:
break;
}
......@@ -1529,7 +1610,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
annotations = getAnnotations(lspObj, ipv4LspIdenTlv, bandwidth, lspType, costType);
td = new DefaultTunnelDescription(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, new DefaultGroupId(
0), providerId, TunnelName.tunnelName(new String(pathNameTlv.getValue())), path,
0), providerId, TunnelName.tunnelName(new String(pathNameTlv.getValue())), path, labelStack,
annotations);
// Do not support PCC initiated LSP after LSP DB sync is completed.
......@@ -1562,7 +1643,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
TunnelId tId = tunnelAdded(td, tunnelState);
Tunnel tunnelInserted = new DefaultTunnel(providerId, tunnelEndPointSrc, tunnelEndPointDst, MPLS,
tunnelState, new DefaultGroupId(0), tId, TunnelName.tunnelName(String.valueOf(pathNameTlv
.getValue())), path, annotations);
.getValue())), path, labelStack, annotations);
PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnelInserted, path, LSP_STATE_RPT);
pcepTunnelData.setStatefulIpv4IndentifierTlv(ipv4LspIdenTlv);
......@@ -1578,7 +1659,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
if (lspObj.getDFlag()) {
annotations = getAnnotations(lspObj, ipv4LspIdenTlv, bandwidth, lspType, costType);
td = new DefaultTunnelDescription(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, new DefaultGroupId(
0), providerId, TunnelName.tunnelName(new String(pathNameTlv.getValue())), path,
0), providerId, TunnelName.tunnelName(new String(pathNameTlv.getValue())), path, labelStack,
annotations);
tunnelUpdateInDelegatedCase(pccId, annotations, td, providerId);
}
......@@ -1618,15 +1699,14 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
*
* @param eroObj ERO object
* @param providerId provider id
* @param cost cost of path
* @return path object
* @return list of links and labels
*/
private Path buildPathFromEroObj(PcepEroObject eroObj, ProviderId providerId, int cost) {
private List<Object> buildPathFromEroObj(PcepEroObject eroObj, ProviderId providerId) {
checkNotNull(eroObj);
List<Link> links = new ArrayList<Link>();
List<Object> subObjList = new ArrayList<>();
LinkedList<PcepValueType> llSubObj = eroObj.getSubObjects();
if (0 == llSubObj.size()) {
log.debug("ERO in report message does not have hop information");
log.error("ERO in report message does not have hop information");
return null;
}
ListIterator<PcepValueType> tlvIterator = llSubObj.listIterator();
......@@ -1654,16 +1734,34 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
.dst(dst)
.type(Link.Type.DIRECT)
.build();
links.add(link);
subObjList.add(link);
src = dst;
}
break;
case SrEroSubObject.TYPE:
SrEroSubObject srEroSubObj = (SrEroSubObject) subObj;
subObjList.add(srEroSubObj.getSid());
if (srEroSubObj.getSt() == PcepNaiIpv4Adjacency.ST_TYPE) {
PcepNaiIpv4Adjacency nai = (PcepNaiIpv4Adjacency) (srEroSubObj.getNai());
IpAddress srcIp = IpAddress.valueOf(nai.getLocalIpv4Addr());
src = new ConnectPoint(IpElementId.ipElement(srcIp), PortNumber.portNumber(0));
IpAddress dstIp = IpAddress.valueOf(nai.getRemoteIpv4Addr());
dst = new ConnectPoint(IpElementId.ipElement(dstIp), PortNumber.portNumber(0));
Link link = DefaultLink.builder()
.providerId(providerId)
.src(src)
.dst(dst)
.type(Link.Type.DIRECT)
.build();
subObjList.add(link);
}
default:
// the other sub objects are not required
}
}
return new DefaultPath(providerId, links, cost, EMPTY);
return subObjList;
}
@Override
......