import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import java.util.List;
-
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
import org.opendaylight.protocol.pcep.spi.MessageUtil;
import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
/**
* Parser for {@link Pcinitiate}
*/
-public final class CInitiated00PCInitiateMessageParser extends AbstractMessageParser {
+public class CInitiated00PCInitiateMessageParser extends AbstractMessageParser {
public static final int TYPE = 12;
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.pcinitiate.message.PcinitiateMessage init = ((Pcinitiate) message).getPcinitiateMessage();
ByteBuf buffer = Unpooled.buffer();
for (final Requests req : init.getRequests()) {
- serializeObject(req.getSrp(), buffer);
- serializeObject(req.getLsp(), buffer);
- if (req.getEndpointsObj() != null) {
- serializeObject(req.getEndpointsObj(), buffer);
- }
- if (req.getEro() != null) {
- serializeObject(req.getEro(), buffer);
- }
- if (req.getLspa() != null) {
- serializeObject(req.getLspa(), buffer);
- }
- if (req.getBandwidth() != null) {
- serializeObject(req.getBandwidth(), buffer);
- }
- if (req.getMetrics() != null && !req.getMetrics().isEmpty()) {
- for (final Metrics m : req.getMetrics()) {
- serializeObject(m.getMetric(), buffer);
- }
- }
- if (req.getIro() != null) {
- serializeObject(req.getIro(), buffer);
- }
+ serializeRequest(req, buffer);
}
MessageUtil.formatMessage(TYPE, buffer, out);
}
+ protected void serializeRequest(final Requests req, final ByteBuf buffer) {
+ serializeObject(req.getSrp(), buffer);
+ serializeObject(req.getLsp(), buffer);
+ if (req.getEndpointsObj() != null) {
+ serializeObject(req.getEndpointsObj(), buffer);
+ }
+ if (req.getEro() != null) {
+ serializeObject(req.getEro(), buffer);
+ }
+ if (req.getLspa() != null) {
+ serializeObject(req.getLspa(), buffer);
+ }
+ if (req.getBandwidth() != null) {
+ serializeObject(req.getBandwidth(), buffer);
+ }
+ if (req.getMetrics() != null && !req.getMetrics().isEmpty()) {
+ for (final Metrics m : req.getMetrics()) {
+ serializeObject(m.getMetric(), buffer);
+ }
+ }
+ if (req.getIro() != null) {
+ serializeObject(req.getIro(), buffer);
+ }
+ }
+
@Override
protected Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
if (objects == null) {
return new PcinitiateBuilder().setPcinitiateMessage(builder.build()).build();
}
- private Requests getValidRequest(final List<Object> objects) {
+ protected Requests getValidRequest(final List<Object> objects) {
final RequestsBuilder builder = new RequestsBuilder();
builder.setSrp((Srp) objects.get(0));
objects.remove(0);
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import java.util.List;
-
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
import org.opendaylight.protocol.pcep.spi.MessageUtil;
import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
/**
* Parser for {@link Pcrpt}
*/
-public final class Stateful07PCReportMessageParser extends AbstractMessageParser {
+public class Stateful07PCReportMessageParser extends AbstractMessageParser {
public static final int TYPE = 10;
final List<Reports> reports = msg.getPcrptMessage().getReports();
ByteBuf buffer = Unpooled.buffer();
for (final Reports report : reports) {
- if (report.getSrp() != null) {
- serializeObject(report.getSrp(), buffer);
+ serializeReport(report, buffer);
+ }
+ MessageUtil.formatMessage(TYPE, buffer, out);
+ }
+
+ protected void serializeReport(final Reports report, final ByteBuf buffer) {
+ if (report.getSrp() != null) {
+ serializeObject(report.getSrp(), buffer);
+ }
+ serializeObject(report.getLsp(), buffer);
+ final Path p = report.getPath();
+ if (p != null) {
+ serializeObject(p.getEro(), buffer);
+ if (p.getLspa() != null) {
+ serializeObject(p.getLspa(), buffer);
}
- serializeObject(report.getLsp(), buffer);
- final Path p = report.getPath();
- if (p != null) {
- serializeObject(p.getEro(), buffer);
- if (p.getLspa() != null) {
- serializeObject(p.getLspa(), buffer);
- }
- if (p.getBandwidth() != null) {
- serializeObject(p.getBandwidth(), buffer);
- }
- if (p.getMetrics() != null && !p.getMetrics().isEmpty()) {
- for (final Metrics m : p.getMetrics()) {
- serializeObject(m.getMetric(), buffer);
- }
- }
- if (p.getIro() != null) {
- serializeObject(p.getIro(), buffer);
- }
- if (p.getRro() != null) {
- serializeObject(p.getRro(), buffer);
+ if (p.getBandwidth() != null) {
+ serializeObject(p.getBandwidth(), buffer);
+ }
+ if (p.getMetrics() != null && !p.getMetrics().isEmpty()) {
+ for (final Metrics m : p.getMetrics()) {
+ serializeObject(m.getMetric(), buffer);
}
}
+ if (p.getIro() != null) {
+ serializeObject(p.getIro(), buffer);
+ }
+ if (p.getRro() != null) {
+ serializeObject(p.getRro(), buffer);
+ }
}
- MessageUtil.formatMessage(TYPE, buffer, out);
}
@Override
while (!objects.isEmpty()) {
final Reports report = getValidReports(objects, errors);
- if (reports != null) {
+ if (report != null) {
reports.add(report);
}
}
return new PcrptBuilder().setPcrptMessage(new PcrptMessageBuilder().setReports(reports).build()).build();
}
- private Reports getValidReports(final List<Object> objects, final List<Message> errors) {
+ protected Reports getValidReports(final List<Object> objects, final List<Message> errors) {
+ boolean isValid = true;
final ReportsBuilder builder = new ReportsBuilder();
if (objects.get(0) instanceof Srp) {
builder.setSrp((Srp) objects.get(0));
objects.remove(0);
} else {
errors.add(createErrorMsg(PCEPErrors.LSP_MISSING));
- return null;
+ isValid = false;
}
if (!objects.isEmpty()) {
final PathBuilder pBuilder = new PathBuilder();
+ if (objects.get(0) instanceof Ero) {
+ pBuilder.setEro((Ero) objects.get(0));
+ objects.remove(0);
+ } else {
+ errors.add(createErrorMsg(PCEPErrors.ERO_MISSING));
+ isValid = false;
+ }
parsePath(objects, pBuilder);
builder.setPath(pBuilder.build());
}
- return builder.build();
+ if(isValid) {
+ return builder.build();
+ }
+ return null;
}
private void parsePath(final List<Object> objects, final PathBuilder builder) {
obj = objects.get(0);
switch (state) {
case Init:
- state = State.EroIn;
- if (obj instanceof Ero) {
- builder.setEro((Ero) obj);
- break;
- }
- case EroIn:
state = State.LspaIn;
if (obj instanceof Lspa) {
builder.setLspa((Lspa) obj);
}
private enum State {
- Init, EroIn, LspaIn, BandwidthIn, MetricIn, IroIn, RroIn, End
+ Init, LspaIn, BandwidthIn, MetricIn, IroIn, RroIn, End
}
}
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import java.util.List;
-
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
import org.opendaylight.protocol.pcep.spi.MessageUtil;
import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
/**
* Parser for {@link Pcupd}
*/
-public final class Stateful07PCUpdateRequestMessageParser extends AbstractMessageParser {
+public class Stateful07PCUpdateRequestMessageParser extends AbstractMessageParser {
public static final int TYPE = 11;
final List<Updates> updates = msg.getPcupdMessage().getUpdates();
ByteBuf buffer = Unpooled.buffer();
for (final Updates update : updates) {
- serializeObject(update.getSrp(), buffer);
- serializeObject(update.getLsp(), buffer);
- final Path p = update.getPath();
- if (p != null) {
- serializeObject(p.getEro(), buffer);
- if (p.getLspa() != null) {
- serializeObject(p.getLspa(), buffer);
- }
- if (p.getBandwidth() != null) {
- serializeObject(p.getBandwidth(), buffer);
- }
- if (p.getMetrics() != null && !p.getMetrics().isEmpty()) {
- for (final Metrics m : p.getMetrics()) {
- serializeObject(m.getMetric(), buffer);
- }
- }
- if (p.getIro() != null) {
- serializeObject(p.getIro(), buffer);
+ serializeUpdate(update, buffer);
+ }
+ MessageUtil.formatMessage(TYPE, buffer, out);
+ }
+
+ protected void serializeUpdate(final Updates update, final ByteBuf buffer) {
+ serializeObject(update.getSrp(), buffer);
+ serializeObject(update.getLsp(), buffer);
+ final Path p = update.getPath();
+ if (p != null) {
+ serializeObject(p.getEro(), buffer);
+ if (p.getLspa() != null) {
+ serializeObject(p.getLspa(), buffer);
+ }
+ if (p.getBandwidth() != null) {
+ serializeObject(p.getBandwidth(), buffer);
+ }
+ if (p.getMetrics() != null && !p.getMetrics().isEmpty()) {
+ for (final Metrics m : p.getMetrics()) {
+ serializeObject(m.getMetric(), buffer);
}
}
+ if (p.getIro() != null) {
+ serializeObject(p.getIro(), buffer);
+ }
}
- MessageUtil.formatMessage(TYPE, buffer, out);
}
@Override
final List<Updates> updateRequests = Lists.newArrayList();
while (!objects.isEmpty()) {
- final Updates update = getValidUpdates(objects, errors);
- if (update != null) {
- updateRequests.add(update);
+ final Updates upd = getValidUpdates(objects, errors);
+ if(upd != null) {
+ updateRequests.add(upd);
}
}
if (!objects.isEmpty()) {
return new PcupdBuilder().setPcupdMessage(new PcupdMessageBuilder().setUpdates(updateRequests).build()).build();
}
- private Updates getValidUpdates(final List<Object> objects, final List<Message> errors) {
+ protected Updates getValidUpdates(final List<Object> objects, final List<Message> errors) {
+ boolean isValid = true;
final UpdatesBuilder builder = new UpdatesBuilder();
if (objects.get(0) instanceof Srp) {
builder.setSrp((Srp) objects.get(0));
objects.remove(0);
} else {
errors.add(createErrorMsg(PCEPErrors.SRP_MISSING));
- return null;
+ isValid = false;
}
if (objects.get(0) instanceof Lsp) {
builder.setLsp((Lsp) objects.get(0));
objects.remove(0);
} else {
errors.add(createErrorMsg(PCEPErrors.LSP_MISSING));
- return null;
+ isValid = false;
}
if (!objects.isEmpty()) {
final PathBuilder pBuilder = new PathBuilder();
objects.remove(0);
} else {
errors.add(createErrorMsg(PCEPErrors.ERO_MISSING));
- return null;
+ isValid = false;
}
parsePath(objects, pBuilder);
builder.setPath(pBuilder.build());
}
- return builder.build();
+ if(isValid) {
+ return builder.build();
+ }
+ return null;
}
private void parsePath(final List<Object> objects, final PathBuilder pBuilder) {
uses initiated-capability-tlv;
}
- augment "/nt:network-topology/nt:topology/nt:node/topo:path-computation-client/topo:reported-lsp/stateful:lsp" {
+ augment "/nt:network-topology/nt:topology/nt:node/topo:path-computation-client/topo:reported-lsp/topo:path/stateful:lsp" {
reference "http://tools.ietf.org/html/draft-ietf-pce-pce-initiated-lsp-00#section-5.3.1";
leaf create {
type boolean;
ext:augment-identifier tlvs-3;
}
- augment "/nt:network-topology/nt:topology/nt:node/topo:path-computation-client/topo:reported-lsp" {
+ augment "/nt:network-topology/nt:topology/nt:node/topo:path-computation-client/topo:reported-lsp/topo:path" {
uses lsp-object;
}
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import com.google.common.collect.Lists;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import java.io.IOException;
import java.util.Collections;
import java.util.List;
-
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.protocol.pcep.ietf.initiated00.CInitiated00PCInitiateMessageParser;
assertArrayEquals(result.array(), buf.array());
}
}
+
+ @Test
+ public void testMissingLspObjectErrorInPcRptMsg() throws PCEPDeserializerException {
+ final byte[] statefulMsg= {
+ 0x20,0x0B,0x00,0x1C,
+ /* srp-object */
+ 0x21,0x10,0x00,0x0C,
+ 0x00,0x00,0x00,0x001,
+ 0x00,0x00,0x00,0x01,
+ /* lsp-object is missing*/
+ /* sr-ero-object */
+ 0x07,0x10,0x00,0x0C,
+ /* ipv4 prefix subobject */
+ (byte) 0x81,0x08,(byte) 0xFF,(byte) 0xFF,
+ (byte) 0xFF,(byte) 0xFF,0x16,0x00};
+
+ final Stateful07PCReportMessageParser parser = new Stateful07PCReportMessageParser(this.ctx.getObjectHandlerRegistry());
+
+ final PcerrMessageBuilder errMsgBuilder = new PcerrMessageBuilder();
+ errMsgBuilder.setErrors(Lists.newArrayList(new ErrorsBuilder().setErrorObject(
+ new ErrorObjectBuilder().setType((short) 6).setValue((short) 8).build()).build()));
+ final PcerrBuilder builder = new PcerrBuilder();
+ builder.setPcerrMessage(errMsgBuilder.build());
+
+ ByteBuf buf = Unpooled.wrappedBuffer(statefulMsg);
+ final List<Message> errors = Lists.<Message>newArrayList();
+ parser.parseMessage(buf.slice(4, buf.readableBytes() - 4), errors);
+ assertFalse(errors.isEmpty());
+ assertEquals(builder.build(), errors.get(0));
+ }
}
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import java.util.List;
-
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
import org.opendaylight.protocol.pcep.spi.MessageUtil;
import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
if (reply.getRp() == null) {
throw new IllegalArgumentException("Reply must contain RP object.");
}
- serializeObject(reply.getRp(), buffer);
- if (reply.getResult() != null) {
- if (reply.getResult() instanceof FailureCase) {
- final FailureCase f = ((FailureCase) reply.getResult());
- serializeObject(f.getNoPath(), buffer);
- if (f.getLspa() != null) {
- serializeObject(f.getLspa(), buffer);
+ serializeReply(reply, buffer);
+ }
+ MessageUtil.formatMessage(TYPE, buffer, out);
+ }
+
+ protected void serializeReply(final Replies reply, final ByteBuf buffer) {
+ serializeObject(reply.getRp(), buffer);
+ if (reply.getResult() != null) {
+ if (reply.getResult() instanceof FailureCase) {
+ final FailureCase f = ((FailureCase) reply.getResult());
+ serializeObject(f.getNoPath(), buffer);
+ if (f.getLspa() != null) {
+ serializeObject(f.getLspa(), buffer);
+ }
+ if (f.getBandwidth() != null) {
+ serializeObject(f.getBandwidth(), buffer);
+ }
+ if (f.getMetrics() != null && !f.getMetrics().isEmpty()) {
+ for (final Metrics m : f.getMetrics()) {
+ serializeObject(m.getMetric(), buffer);
+ }
+ }
+ if (f.getIro() != null) {
+ serializeObject(f.getIro(), buffer);
+ }
+ } else {
+ final SuccessCase s = (SuccessCase) reply.getResult();
+ for (final Paths p : s.getSuccess().getPaths()) {
+ serializeObject(p.getEro(), buffer);
+ if (p.getLspa() != null) {
+ serializeObject(p.getLspa(), buffer);
+ }
+ if (p.getOf() != null) {
+ serializeObject(p.getOf(), buffer);
}
- if (f.getBandwidth() != null) {
- serializeObject(f.getBandwidth(), buffer);
+ if (p.getBandwidth() != null) {
+ serializeObject(p.getBandwidth(), buffer);
}
- if (f.getMetrics() != null && !f.getMetrics().isEmpty()) {
- for (final Metrics m : f.getMetrics()) {
+ if (p.getMetrics() != null && !p.getMetrics().isEmpty()) {
+ for (final Metrics m : p.getMetrics()) {
serializeObject(m.getMetric(), buffer);
}
}
- if (f.getIro() != null) {
- serializeObject(f.getIro(), buffer);
- }
- } else {
- final SuccessCase s = (SuccessCase) reply.getResult();
- for (final Paths p : s.getSuccess().getPaths()) {
- serializeObject(p.getEro(), buffer);
- if (p.getLspa() != null) {
- serializeObject(p.getLspa(), buffer);
- }
- if (p.getOf() != null) {
- serializeObject(p.getOf(), buffer);
- }
- if (p.getBandwidth() != null) {
- serializeObject(p.getBandwidth(), buffer);
- }
- if (p.getMetrics() != null && !p.getMetrics().isEmpty()) {
- for (final Metrics m : p.getMetrics()) {
- serializeObject(m.getMetric(), buffer);
- }
- }
- if (p.getIro() != null) {
- serializeObject(p.getIro(), buffer);
- }
+ if (p.getIro() != null) {
+ serializeObject(p.getIro(), buffer);
}
}
}
}
- MessageUtil.formatMessage(TYPE, buffer, out);
}
@Override
Preconditions.checkArgument(object instanceof Lspa, "Wrong instance of PCEPObject. Passed %s. Needed LspaObject.", object.getClass());
final Lspa lspaObj = (Lspa) object;
final ByteBuf body = Unpooled.buffer();
- body.writeInt(lspaObj.getExcludeAny().getValue().intValue());
- body.writeInt(lspaObj.getIncludeAny().getValue().intValue());
- body.writeInt(lspaObj.getIncludeAll().getValue().intValue());
- body.writeByte(lspaObj.getSetupPriority());
- body.writeByte(lspaObj.getHoldPriority());
+ if (lspaObj.getExcludeAny() != null) {
+ body.writeInt(lspaObj.getExcludeAny().getValue().intValue());
+ } else {
+ body.writeZero(Integer.SIZE / Byte.SIZE);
+ }
+ if (lspaObj.getIncludeAny() != null) {
+ body.writeInt(lspaObj.getIncludeAny().getValue().intValue());
+ } else {
+ body.writeZero(Integer.SIZE / Byte.SIZE);
+ }
+ if (lspaObj.getIncludeAll() != null) {
+ body.writeInt(lspaObj.getIncludeAll().getValue().intValue());
+ } else {
+ body.writeZero(Integer.SIZE / Byte.SIZE);
+ }
+ if (lspaObj.getSetupPriority() != null) {
+ body.writeByte(lspaObj.getSetupPriority());
+ } else {
+ body.writeZero(1);
+ }
+ if (lspaObj.getHoldPriority() != null) {
+ body.writeByte(lspaObj.getHoldPriority());
+ } else {
+ body.writeZero(1);
+ }
final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
if (lspaObj.isLocalProtectionDesired() != null) {
flags.set(L_FLAG_OFFSET, lspaObj.isLocalProtectionDesired());
import network-topology { prefix nt; revision-date 2013-10-21; }
import odl-network-topology { prefix ont; revision-date 2014-01-13; }
import pcep-types { prefix pcep; revision-date 2013-10-05; }
+ import rsvp { prefix rsvp; revision-date 2013-08-20; }
organization "Cisco Systems, Inc.";
contact "Robert Varga <rovarga@cisco.com>";
}
key name;
- container path {
+ list path {
+ leaf lsp-id {
+ type rsvp:lsp-id;
+ mandatory true;
+ }
+ key lsp-id;
+
uses pcep:path-definition;
}
-
uses lsp-metadata;
}
}
import io.netty.util.concurrent.FutureListener;
import java.net.InetAddress;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.MessageHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLsp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLspBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLspKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.Path;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
}
protected final synchronized void updateLsp(final DataModificationTransaction trans, final L id, final String lspName,
- final ReportedLspBuilder rlb, final boolean solicited) {
+ final ReportedLspBuilder rlb, final boolean solicited, final boolean remove) {
final String name;
if (lspName == null) {
LOG.debug("Saved LSP {} with name {}", id, name);
this.lsps.put(id, name);
+ // just one path should be reported
+ Preconditions.checkState(rlb.getPath().size() == 1);
+ LspId reportedLspId = rlb.getPath().get(0).getLspId();
+ // check previous report for existing paths
+ ReportedLsp previous = this.lspData.get(name);
+ // if no previous report about the lsp exist, just proceed
+ if (previous != null) {
+ List<Path> updatedPaths = new ArrayList<>(previous.getPath());
+ LOG.debug("Found previous paths {} to this lsp name {}", updatedPaths, name);
+ for (Path path : previous.getPath()) {
+ //we found reported path in previous reports
+ if (path.getLspId().getValue() == 0 || path.getLspId().equals(reportedLspId)) {
+ LOG.debug("Match on lsp-id {}", path.getLspId().getValue() );
+ // path that was reported previously and does have the same lsp-id, path will be updated
+ final boolean r = updatedPaths.remove(path);
+ LOG.trace("Request removed? {}", r);
+ }
+ }
+ // if the path does not exist in previous report, add it to path list, it's a new ERO
+ // only one path will be added
+ //lspId is 0 means confirmation message that shouldn't be added (because we have no means of deleting it later)
+ LOG.trace("Adding new path {} to {}", rlb.getPath(), updatedPaths);
+ updatedPaths.addAll(rlb.getPath());
+ if (remove) {
+ if (reportedLspId.getValue() == 0) {
+ // if lsp-id also 0, remove all paths
+ LOG.debug("Removing all paths.");
+ updatedPaths.clear();
+ } else {
+ // path is marked to be removed
+ LOG.debug("Removing path {} from {}", rlb.getPath(), updatedPaths);
+ final boolean r = updatedPaths.removeAll(rlb.getPath());
+ LOG.trace("Request removed? {}", r);
+ }
+ }
+ // if all paths or the last path were deleted, delete whole tunnel
+ if (updatedPaths.isEmpty()) {
+ LOG.debug("All paths were removed, removing LSP with {}.", id);
+ removeLsp(trans, id);
+ return;
+ }
+ LOG.debug("Setting new paths {} to lsp {}", updatedPaths, name);
+ rlb.setPath(updatedPaths);
+ }
Preconditions.checkState(name != null);
rlb.setKey(new ReportedLspKey(name));
rlb.setName(name);
if (r.getPath() != null) {
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.PathBuilder pb = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.PathBuilder();
pb.fieldsFrom(r.getPath());
- rlb.setPath(pb.build());
+ rlb.setPath(Collections.singletonList(pb.build()));
}
boolean solicited = false;
}
if (!lsp.isRemove()) {
- updateLsp(trans, id, name, rlb, solicited);
+ updateLsp(trans, id, name, rlb, solicited, false);
LOG.debug("LSP {} updated", lsp);
} else {
removeLsp(trans, id);
import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
import com.google.common.util.concurrent.ListenableFuture;
import java.net.InetAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Arguments2;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Arguments3;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.OperationalStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Path1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Path1Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.PcrptMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.PcupdBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.PlspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.ReportedLsp1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.ReportedLsp1Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SrpIdNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.StatefulTlv1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.StatefulTlv1Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcerrMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.Tlvs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspArgs;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
}
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.PcrptMessage rpt = ((PcrptMessage) message).getPcrptMessage();
- for (final Reports r : rpt.getReports()) {
- final Lsp lsp = r.getLsp();
+ for (final Reports report : rpt.getReports()) {
+ final Lsp lsp = report.getLsp();
+ final PlspId plspid = lsp.getPlspId();
- if (!lsp.isSync() && (lsp.getPlspId() == null || lsp.getPlspId().getValue() == 0)) {
+ if (!lsp.isSync() && (lsp.getPlspId() == null || plspid.getValue() == 0)) {
stateSynchronizationAchieved(trans);
continue;
}
final ReportedLspBuilder rlb = new ReportedLspBuilder();
- rlb.addAugmentation(ReportedLsp1.class, new ReportedLsp1Builder(r).build());
- if (r.getPath() != null) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.PathBuilder pb = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.PathBuilder();
- pb.fieldsFrom(r.getPath());
- rlb.setPath(pb.build());
- }
+
boolean solicited = false;
- final Srp srp = r.getSrp();
+ final Srp srp = report.getSrp();
if (srp != null) {
final SrpIdNumber id = srp.getOperationId();
if (id.getValue() != 0) {
// up...
break;
}
- }
- }
- final PlspId id = lsp.getPlspId();
- if (!lsp.isRemove()) {
- final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.Tlvs tlvs = r.getLsp().getTlvs();
- final String name;
- if (tlvs != null && tlvs.getSymbolicPathName() != null) {
- name = Charsets.UTF_8.decode(ByteBuffer.wrap(tlvs.getSymbolicPathName().getPathName().getValue())).toString();
- } else {
- name = null;
}
-
- updateLsp(trans, id, name, rlb, solicited);
- LOG.debug("LSP {} updated", lsp);
+ }
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.Tlvs tlvs = report.getLsp().getTlvs();
+ final String name;
+ if (tlvs != null && tlvs.getSymbolicPathName() != null) {
+ name = Charsets.UTF_8.decode(ByteBuffer.wrap(tlvs.getSymbolicPathName().getPathName().getValue())).toString();
} else {
- removeLsp(trans, id);
- LOG.debug("LSP {} removed", lsp);
+ name = null;
}
+ LspId lspid = null;
+ if (tlvs != null && tlvs.getLspIdentifiers() != null) {
+ lspid = tlvs.getLspIdentifiers().getLspId();
+ }
+ if (report.getPath() != null) {
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.PathBuilder pb = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.PathBuilder();
+ pb.fieldsFrom(report.getPath());
+ pb.addAugmentation(Path1.class, new Path1Builder().setLsp(report.getLsp()).build());
+ pb.setLspId(lspid);
+ rlb.setPath(Lists.newArrayList(pb.build()));
+ }
+ updateLsp(trans, plspid, name, rlb, solicited, lsp.isRemove());
+ LOG.debug("LSP {} updated", lsp);
}
-
return false;
}
@Override
public synchronized ListenableFuture<OperationResult> removeLsp(final RemoveLspArgs input) {
Preconditions.checkArgument(input != null && input.getName() != null & input.getNode() != null, "Mandatory XML tags are missing.");
+ LOG.trace("RemoveLspArgs {}", input);
// Make sure the LSP exists, we need it for PLSP-ID
final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName()).build();
final ReportedLsp rep = readOperationalData(lsp);
LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
return OperationResults.UNSENT.future();
}
-
- final ReportedLsp1 ra = rep.getAugmentation(ReportedLsp1.class);
+ // it doesn't matter how many lsps there are in the path list, we only need delegate & plspid that is the same in eeach path
+ final Path1 ra = rep.getPath().get(0).getAugmentation(Path1.class);
Preconditions.checkState(ra != null, "Reported LSP reported null from data-store.");
Lsp reportedLsp = ra.getLsp();
Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object.");
@Override
public synchronized ListenableFuture<OperationResult> updateLsp(final UpdateLspArgs input) {
Preconditions.checkArgument(input != null && input.getName() != null & input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing.");
+ LOG.trace("UpdateLspArgs {}", input);
// Make sure the LSP exists
final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName()).build();
final ReportedLsp rep = readOperationalData(lsp);
LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
return OperationResults.UNSENT.future();
}
- final ReportedLsp1 ra = rep.getAugmentation(ReportedLsp1.class);
+ // it doesn't matter how many lsps there are in the path list, we only need plspid that is the same in each path
+ final Path1 ra = rep.getPath().get(0).getAugmentation(Path1.class);
Preconditions.checkState(ra != null, "Reported LSP reported null from data-store.");
Lsp reportedLsp = ra.getLsp();
Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object.");
LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
return OperationResults.UNSENT.future();
}
-
- final ReportedLsp1 ra = rep.getAugmentation(ReportedLsp1.class);
- if (ra == null) {
- LOG.warn("Node {} LSP {} does not contain data", input.getNode(), input.getName());
- return OperationResults.UNSENT.future();
+ boolean operational = false;
+ // check if at least one of the paths has the same status as requested
+ for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.Path p : rep.getPath()) {
+ Path1 p1 = p.getAugmentation(Path1.class);
+ if (p1 == null) {
+ LOG.warn("Node {} LSP {} does not contain data", input.getNode(), input.getName());
+ return OperationResults.UNSENT.future();
+ }
+ Lsp l = p1.getLsp();
+ if (l.getOperational().equals(op)) {
+ operational = true;
+ }
}
-
- if (ra.getLsp().getOperational().equals(op)) {
+ if (operational) {
return OperationResults.SUCCESS.future();
} else {
return OperationResults.UNSENT.future();
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.PcrptMessageBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.Reports;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.ReportsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.reports.PathBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.symbolic.path.name.tlv.SymbolicPathNameBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
final DefaultPCEPSessionNegotiator neg = new DefaultPCEPSessionNegotiator(new HashedWheelTimer(), mock(Promise.class), this.clientListener, this.manager.getSessionListener(), (short) 1, 5, this.localPrefs);
this.session = neg.createSession(new HashedWheelTimer(), this.clientListener, this.localPrefs, this.localPrefs);
- final List<Reports> reports = Lists.newArrayList(new ReportsBuilder().setLsp(
+ final List<Reports> reports = Lists.newArrayList(new ReportsBuilder().setPath(new PathBuilder().setEro(new EroBuilder().build()).build()).setLsp(
new LspBuilder().setPlspId(new PlspId(5L)).setSync(false).setRemove(false).setTlvs(
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder().setSymbolicPathName(
new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(new byte[] { 22, 34 })).build()).build()).build()).build());
import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.AdministrativeStatus;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.ReportedLsp1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Path1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.identifiers.tlv.lsp.identifiers.AddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv4Case;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv6Case;
private void create(final DataModificationTransaction trans, final InstanceIdentifier<ReportedLsp> i, final ReportedLsp value) {
final InstanceIdentifier<Node> ni = i.firstIdentifierOf(Node.class);
- final ReportedLsp1 rl = value.getAugmentation(ReportedLsp1.class);
+
+ final Path1 rl = value.getPath().get(0).getAugmentation(Path1.class);
final AddressFamily af = rl.getLsp().getTlvs().getLspIdentifiers().getAddressFamily();
throw new IllegalArgumentException("Unsupported address family: " + af.getImplementedInterface());
}
- final Link1Builder lab = new Link1Builder(value.getPath().getLspa());
- lab.setBandwidth(value.getPath().getBandwidth().getBandwidth());
- lab.setClassType(value.getPath().getClassType().getClassType());
+ final Link1Builder lab = new Link1Builder(value.getPath().get(0).getLspa());
+ lab.setBandwidth(value.getPath().get(0).getBandwidth().getBandwidth());
+ lab.setClassType(value.getPath().get(0).getClassType().getClassType());
lab.setSymbolicPathName(value.getName());
final InstanceIdentifier<TerminationPoint> dst = getIpTerminationPoint(trans, dstIp, null, Boolean.FALSE);