}
private void processRoute(final DOMDataWriteTransaction tx, final RIBSupport ribSupport, final AbstractImportPolicy policy, final YangInstanceIdentifier routesPath, final DataTreeCandidateNode route) {
+ LOG.debug("Process route {}", route);
switch (route.getModificationType()) {
case DELETE:
// Delete has already been affected by the store in caller, so this is a no-op.
@Override
public void onDataTreeChanged(final Collection<DataTreeCandidate> changes) {
+ LOG.trace("Data changed called to effective RIB. Change : {}", changes);
final DOMDataWriteTransaction tx = this.chain.newWriteOnlyTransaction();
for (final DataTreeCandidate tc : changes) {
private final BindingTransactionChain chain;
private final AsNumber localAs;
private final Ipv4Address bgpIdentifier;
- private final Ipv4Address clusterId;
+ private final ClusterIdentifier clusterId;
private final Set<BgpTableType> localTables;
private final RIBTables tables;
private final BlockingQueue<Peer> peers;
public RIBImpl(final RibId ribId, final AsNumber localAs, final Ipv4Address localBgpId, final Ipv4Address clusterId, final RIBExtensionConsumerContext extensions,
final BGPDispatcher dispatcher, final ReconnectStrategyFactory tcpStrategyFactory, final BindingCodecTreeFactory codecFactory,
- final ReconnectStrategyFactory sessionStrategyFactory, final DataBroker dps, final DOMDataBroker domDataBroker, final List<BgpTableType> localTables, GeneratedClassLoadingStrategy classStrategy) {
+ final ReconnectStrategyFactory sessionStrategyFactory, final DataBroker dps, final DOMDataBroker domDataBroker, final List<BgpTableType> localTables, final GeneratedClassLoadingStrategy classStrategy) {
super(InstanceIdentifier.create(BgpRib.class).child(Rib.class, new RibKey(Preconditions.checkNotNull(ribId))));
this.chain = dps.createTransactionChain(this);
this.localAs = Preconditions.checkNotNull(localAs);
this.comparator = new BGPObjectComparator(localAs);
this.bgpIdentifier = Preconditions.checkNotNull(localBgpId);
- this.clusterId = clusterId == null ? localBgpId : clusterId;
+ this.clusterId = (clusterId == null) ? new ClusterIdentifier(localBgpId) : new ClusterIdentifier(clusterId);
this.dispatcher = Preconditions.checkNotNull(dispatcher);
this.sessionStrategyFactory = Preconditions.checkNotNull(sessionStrategyFactory);
this.tcpStrategyFactory = Preconditions.checkNotNull(tcpStrategyFactory);
final WriteTransaction trans = this.chain.newWriteOnlyTransaction();
- final PolicyDatabase pd = new PolicyDatabase(localAs.getValue(), localBgpId, new ClusterIdentifier(localBgpId));
- /*if (clusterId == null) {
- clusterId is not present, fallback to bgpId
- pd = new PolicyDatabase(localAs.getValue(), localBgpId, new ClusterIdentifier(localBgpId));
- } else {
- pd = new PolicyDatabase(as, bgpId, clusterId);
- } */
+ final PolicyDatabase pd = new PolicyDatabase(localAs.getValue(), localBgpId, this.clusterId);
final DOMDataBrokerExtension service = this.domDataBroker.getSupportedExtensions().get(DOMDataTreeChangeService.class);
final DOMTransactionChain domChain = this.createPeerChain(this);
- // put clusterId
EffectiveRibInWriter.create((DOMDataTreeChangeService) service, domChain, getYangRibId(), pd, this.ribContextRegistry);
+ LOG.debug("Effective RIB created.");
// put empty BgpRib if not exists
trans.put(LogicalDatastoreType.OPERATIONAL, getInstanceIdentifier(),
}
private boolean handleMessageOpenWait(final Message msg) {
- if (msg instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Open) {
- final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessage o = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Open) msg).getOpenMessage();
- final Open open = o.getOpen();
- if (isProposalAcceptable(open)) {
- this.sendMessage(KEEPALIVE);
- this.remotePrefs = open;
- this.remoteOK = true;
- if (this.localOK) {
- negotiationSuccessful(createSession(this.channel, this.localPrefs, this.remotePrefs));
- LOG.info("PCEP peer {} completed negotiation", this.channel);
- this.state = State.FINISHED;
- } else {
- scheduleFailTimer();
- this.state = State.KEEP_WAIT;
- LOG.debug("Channel {} moved to KeepWait state with remoteOK=1", this.channel);
- }
- return true;
- }
-
- if (this.openRetry) {
- sendErrorMessage(PCEPErrors.SECOND_OPEN_MSG);
- negotiationFailed(new IllegalStateException("OPEN renegotiation failed"));
- this.state = State.FINISHED;
- return true;
- }
-
- final Open newPrefs = getCounterProposal(open);
- if (newPrefs == null) {
- sendErrorMessage(PCEPErrors.NON_ACC_NON_NEG_SESSION_CHAR);
- negotiationFailed(new IllegalStateException("Peer sent unacceptable session parameters"));
+ if (!(msg instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Open)) {
+ return false;
+ }
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessage o = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Open) msg).getOpenMessage();
+ final Open open = o.getOpen();
+ if (isProposalAcceptable(open)) {
+ this.sendMessage(KEEPALIVE);
+ this.remotePrefs = open;
+ this.remoteOK = true;
+ if (this.localOK) {
+ negotiationSuccessful(createSession(this.channel, this.localPrefs, this.remotePrefs));
+ LOG.info("PCEP peer {} completed negotiation", this.channel);
this.state = State.FINISHED;
- return true;
+ } else {
+ scheduleFailTimer();
+ this.state = State.KEEP_WAIT;
+ LOG.debug("Channel {} moved to KeepWait state with remoteOK=1", this.channel);
}
-
- this.sendMessage(Util.createErrorMessage(PCEPErrors.NON_ACC_NEG_SESSION_CHAR, newPrefs));
-
- this.openRetry = true;
- this.state = this.localOK ? State.OPEN_WAIT : State.KEEP_WAIT;
- scheduleFailTimer();
return true;
}
- return false;
+ if (this.openRetry) {
+ sendErrorMessage(PCEPErrors.SECOND_OPEN_MSG);
+ negotiationFailed(new IllegalStateException("OPEN renegotiation failed"));
+ this.state = State.FINISHED;
+ return true;
+ }
+ final Open newPrefs = getCounterProposal(open);
+ if (newPrefs == null) {
+ sendErrorMessage(PCEPErrors.NON_ACC_NON_NEG_SESSION_CHAR);
+ negotiationFailed(new IllegalStateException("Peer sent unacceptable session parameters"));
+ this.state = State.FINISHED;
+ return true;
+ }
+ this.sendMessage(Util.createErrorMessage(PCEPErrors.NON_ACC_NEG_SESSION_CHAR, newPrefs));
+ this.openRetry = true;
+ this.state = this.localOK ? State.OPEN_WAIT : State.KEEP_WAIT;
+ scheduleFailTimer();
+ return true;
}
@Override
package org.opendaylight.protocol.pcep.impl;
import java.util.Arrays;
+import java.util.List;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder;
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.Object;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPce;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPceBuilder;
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.overload.object.Overload;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessageBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.ErrorsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.SessionCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.session._case.SessionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTime;
/**
* Utilities used in pcep-impl
new PcerrMessageBuilder().setErrors(Arrays.asList(new ErrorsBuilder().setErrorObject(err).build())).setErrorType(type).build()).build();
}
}
+
+ public static MetricPce validateMonitoringMetrics(final List<Object> objects) throws PCEPDeserializerException {
+ final MetricPceBuilder metricPceBuilder = new MetricPceBuilder();
+ if (!(objects.get(0) instanceof PceId)) {
+ throw new PCEPDeserializerException("metric-pce-list must start with PCE-ID object.");
+ }
+ metricPceBuilder.setPceId((PceId) (objects.get(0)));
+ objects.remove(0);
+ State state = State.START;
+ while (!objects.isEmpty() && !state.equals(State.END)) {
+ final Object obj = objects.get(0);
+ switch(state) {
+ case START :
+ state = State.PROC_TIME;
+ if (obj instanceof ProcTime) {
+ metricPceBuilder.setProcTime((ProcTime) obj);
+ break;
+ }
+ case PROC_TIME :
+ state = State.OVERLOAD;
+ if (obj instanceof Overload) {
+ metricPceBuilder.setOverload((Overload) obj);
+ break;
+ }
+ case OVERLOAD :
+ state = State.END;
+ break;
+ case END :
+ break;
+ default:
+ break;
+ }
+ if (!state.equals(State.END)) {
+ objects.remove(0);
+ }
+ }
+ return metricPceBuilder.build();
+ }
+
+ private enum State {
+ START, PROC_TIME, OVERLOAD, END;
+ }
}
import io.netty.buffer.Unpooled;
import java.util.ArrayList;
import java.util.List;
+import org.opendaylight.protocol.pcep.impl.Util;
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
import org.opendaylight.protocol.pcep.spi.MessageUtil;
import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
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.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPce;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPceBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.GeneralMetricsList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.GeneralMetricsListBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.SpecificMetricsListBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.specific.metrics.list.SpecificMetrics;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.specific.metrics.list.SpecificMetricsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.Overload;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReq;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcmonrep.message.PcmonrepMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcmonrep.message.PcmonrepMessageBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTime;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp;
/**
objects.remove(0);
}
while (!objects.isEmpty() && !(objects.get(0) instanceof Rp)) {
- metricPceList.add(validateMonitoringMetrics(objects));
+ metricPceList.add(Util.validateMonitoringMetrics(objects));
}
if (smb.getRp() != null) {
smb.setMetricPce(metricPceList);
}
return new PcmonrepBuilder().setPcmonrepMessage(builder.build()).build();
}
-
- private MetricPce validateMonitoringMetrics(final List<Object> objects) throws PCEPDeserializerException {
- final MetricPceBuilder metricPceBuilder = new MetricPceBuilder();
- if (!(objects.get(0) instanceof PceId)) {
- throw new PCEPDeserializerException("metric-pce-list must start with PCE-ID object.");
- }
- metricPceBuilder.setPceId((PceId) (objects.get(0)));
- objects.remove(0);
- State state = State.START;
- while (!objects.isEmpty() && !state.equals(State.END)) {
- final Object obj = objects.get(0);
- switch(state) {
- case START :
- state = State.PROC_TIME;
- if (obj instanceof ProcTime) {
- metricPceBuilder.setProcTime((ProcTime) obj);
- break;
- }
- case PROC_TIME :
- state = State.OVERLOAD;
- if (obj instanceof Overload) {
- metricPceBuilder.setOverload((Overload) obj);
- break;
- }
- case OVERLOAD :
- state = State.END;
- break;
- case END :
- break;
- default:
- break;
- }
- if (!state.equals(State.END)) {
- objects.remove(0);
- }
- }
- return metricPceBuilder.build();
- }
-
- private enum State {
- START, PROC_TIME, OVERLOAD, END;
- }
-
}
import io.netty.buffer.Unpooled;
import java.util.ArrayList;
import java.util.List;
+import org.opendaylight.protocol.pcep.impl.Util;
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
import org.opendaylight.protocol.pcep.spi.MessageUtil;
import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.Lspa;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.Metric;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPce;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPceBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.Of;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.Overload;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReq;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.PcrepMessageBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.success._case.SuccessBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.success._case.success.Paths;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTime;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject;
}
if (reply.getResult() instanceof FailureCase) {
final FailureCase f = ((FailureCase) reply.getResult());
- if (f != null) {
- serializeObject(f.getNoPath(), buffer);
- serializeObject(f.getLspa(), buffer);
- serializeObject(f.getBandwidth(), buffer);
- if (f.getMetrics() != null) {
- for (final Metrics m : f.getMetrics()) {
- serializeObject(m.getMetric(), buffer);
- }
- }
- serializeObject(f.getIro(), buffer);
- }
+ serializeFailure(f, buffer);
return;
}
final SuccessCase s = (SuccessCase) reply.getResult();
- if (s != null && s.getSuccess() != null) {
- for (final Paths p : s.getSuccess().getPaths()) {
- serializeObject(p.getEro(), buffer);
- serializeObject(p.getLspa(), buffer);
- serializeObject(p.getOf(), buffer);
- serializeObject(p.getBandwidth(), buffer);
- if (p.getMetrics() != null) {
- for (final Metrics m : p.getMetrics()) {
- serializeObject(m.getMetric(), buffer);
- }
+ serializeSuccess(s, buffer);
+ serializeMonitoringMetrics(reply, buffer);
+ }
+
+ private void serializeFailure(final FailureCase f, final ByteBuf buffer) {
+ if (f == null) {
+ return;
+ }
+ serializeObject(f.getNoPath(), buffer);
+ serializeObject(f.getLspa(), buffer);
+ serializeObject(f.getBandwidth(), buffer);
+ if (f.getMetrics() != null) {
+ for (final Metrics m : f.getMetrics()) {
+ serializeObject(m.getMetric(), buffer);
+ }
+ }
+ serializeObject(f.getIro(), buffer);
+ }
+
+ private void serializeSuccess(final SuccessCase s, final ByteBuf buffer) {
+ if (s == null || s.getSuccess() == null) {
+ return;
+ }
+ for (final Paths p : s.getSuccess().getPaths()) {
+ serializeObject(p.getEro(), buffer);
+ serializeObject(p.getLspa(), buffer);
+ serializeObject(p.getOf(), buffer);
+ serializeObject(p.getBandwidth(), buffer);
+ if (p.getMetrics() != null) {
+ for (final Metrics m : p.getMetrics()) {
+ serializeObject(m.getMetric(), buffer);
}
- serializeObject(p.getIro(), buffer);
}
- serializeVendorInformationObjects(s.getSuccess().getVendorInformationObject(), buffer);
+ serializeObject(p.getIro(), buffer);
}
- serializeMonitoringMetrics(reply, buffer);
+ serializeVendorInformationObjects(s.getSuccess().getVendorInformationObject(), buffer);
}
private void serializeMonitoring(final Replies reply, final ByteBuf buffer) {
Result res = null;
if (!objects.isEmpty()) {
if (objects.get(0) instanceof NoPath) {
- final NoPath noPath = (NoPath) objects.get(0);
- objects.remove(0);
- final FailureCaseBuilder builder = new FailureCaseBuilder();
- builder.setNoPath(noPath);
- while (!objects.isEmpty() && !(objects.get(0) instanceof PceId)) {
- this.parseAttributes(builder, objects);
- }
- res = builder.build();
+ res = handleNoPath((NoPath) objects.get(0), objects);
} else if (objects.get(0) instanceof Ero) {
- final Ero ero = (Ero) objects.get(0);
- objects.remove(0);
- final SuccessBuilder builder = new SuccessBuilder();
- final List<Paths> paths = new ArrayList<>();
- final PathsBuilder pBuilder = new PathsBuilder();
- pBuilder.setEro(ero);
- while (!objects.isEmpty() && !(objects.get(0) instanceof PceId)) {
- final List<VendorInformationObject> vendorInfoObjects = addVendorInformationObjects(objects);
- if (!vendorInfoObjects.isEmpty()) {
- builder.setVendorInformationObject(vendorInfoObjects);
- }
- this.parsePath(pBuilder, objects);
- paths.add(pBuilder.build());
- }
- builder.setPaths(paths);
- res = new SuccessCaseBuilder().setSuccess(builder.build()).build();
+ res = handleEro((Ero) objects.get(0), objects);
}
}
final List<MetricPce> metricPceList = new ArrayList<>();
if (!objects.isEmpty() && objects.get(0) instanceof PceId) {
while (!objects.isEmpty()) {
- metricPceList.add(validateMetricPce(objects));
+ metricPceList.add(Util.validateMonitoringMetrics(objects));
}
}
if (!vendorInfo.isEmpty()) {
return repliesBuilder.setRp(rp).setResult(res).build();
}
+ private Result handleNoPath(final NoPath noPath, final List<Object> objects) {
+ objects.remove(0);
+ final FailureCaseBuilder builder = new FailureCaseBuilder();
+ builder.setNoPath(noPath);
+ while (!objects.isEmpty() && !(objects.get(0) instanceof PceId)) {
+ this.parseAttributes(builder, objects);
+ }
+ return builder.build();
+ }
+
+ private Result handleEro(final Ero ero, final List<Object> objects) {
+ objects.remove(0);
+ final SuccessBuilder builder = new SuccessBuilder();
+ final List<Paths> paths = new ArrayList<>();
+ final PathsBuilder pBuilder = new PathsBuilder();
+ pBuilder.setEro(ero);
+ while (!objects.isEmpty() && !(objects.get(0) instanceof PceId)) {
+ final List<VendorInformationObject> vendorInfoObjects = addVendorInformationObjects(objects);
+ if (!vendorInfoObjects.isEmpty()) {
+ builder.setVendorInformationObject(vendorInfoObjects);
+ }
+ this.parsePath(pBuilder, objects);
+ paths.add(pBuilder.build());
+ }
+ builder.setPaths(paths);
+ return new SuccessCaseBuilder().setSuccess(builder.build()).build();
+ }
+
protected void parseAttributes(final FailureCaseBuilder builder, final List<Object> objects) {
final List<Metrics> pathMetrics = new ArrayList<>();
private enum State {
INIT, LSPA_IN, OF_IN, BANDWIDTH_IN, METRIC_IN, IRO_IN, END
}
-
- protected MetricPce validateMetricPce(final List<Object> objects) throws PCEPDeserializerException {
- final MetricPceBuilder metricPceBuilder = new MetricPceBuilder();
- if (!(objects.get(0) instanceof PceId)) {
- throw new PCEPDeserializerException("metric-pce-list must start with PCE-ID object.");
- }
- metricPceBuilder.setPceId((PceId) (objects.get(0)));
- objects.remove(0);
- MetricPceState state = MetricPceState.START;
- while (!objects.isEmpty() && !state.equals(MetricPceState.END)) {
- final Object obj = objects.get(0);
- switch(state) {
- case START :
- state = MetricPceState.PROC_TIME;
- if (obj instanceof ProcTime) {
- metricPceBuilder.setProcTime((ProcTime) obj);
- break;
- }
- case PROC_TIME :
- state = MetricPceState.OVERLOAD;
- if (obj instanceof Overload) {
- metricPceBuilder.setOverload((Overload) obj);
- break;
- }
- case OVERLOAD :
- state = MetricPceState.END;
- break;
- case END :
- break;
- default:
- break;
- }
- if (!state.equals(MetricPceState.END)) {
- objects.remove(0);
- }
- }
- return metricPceBuilder.build();
- }
-
- private enum MetricPceState {
- START, PROC_TIME, OVERLOAD, END;
- }
}
while (!objects.isEmpty()) {
final RequestsBuilder rBuilder = new RequestsBuilder();
Rp rpObj = null;
- if (objects.get(0) instanceof Rp) {
- rpObj = (Rp) objects.get(0);
- objects.remove(0);
- if (!rpObj.isProcessingRule()) {
- errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.<Rp>absent()));
- } else {
- rBuilder.setRp(rpObj);
- }
- } else {
+ if (!(objects.get(0) instanceof Rp)) {
// if RP obj is missing return error only
errors.add(createErrorMsg(PCEPErrors.RP_MISSING, Optional.<Rp>absent()));
return null;
}
+ rpObj = (Rp) objects.get(0);
+ objects.remove(0);
+ if (!rpObj.isProcessingRule()) {
+ errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.<Rp>absent()));
+ } else {
+ rBuilder.setRp(rpObj);
+ }
final List<VendorInformationObject> vendorInfo = addVendorInformationObjects(objects);
if (!vendorInfo.isEmpty()) {
rBuilder.setVendorInformationObject(vendorInfo);
if (objects.get(0) instanceof PathKey) {
rBuilder.setPathKeyExpansion(new PathKeyExpansionBuilder().setPathKey((PathKey) objects.get(0)).build());
}
- continue;
}
final P2pBuilder p2pBuilder = new P2pBuilder();
private static final int SID_TYPE_BITS_OFFSET = 4;
+ private static class SrSubobjectImpl implements SrSubobject {
+
+ private final boolean m;
+ private final boolean c;
+ private final SidType sidType;
+ private final Long sid;
+ private final Nai nai;
+
+ public SrSubobjectImpl(final boolean m, final boolean c, final SidType sidType,
+ final Long sid, final Nai nai) {
+ this.m = m;
+ this.c = c;
+ this.sidType = sidType;
+ this.sid = sid;
+ this.nai = nai;
+ }
+
+ @Override
+ public Class<? extends DataContainer> getImplementedInterface() {
+ return SrSubobject.class;
+ }
+
+ @Override
+ public Boolean isMFlag() {
+ return this.m;
+ }
+
+ @Override
+ public Boolean isCFlag() {
+ return this.c;
+ }
+
+ @Override
+ public SidType getSidType() {
+ return this.sidType;
+ }
+
+ @Override
+ public Long getSid() {
+ return this.sid;
+ }
+
+ @Override
+ public Nai getNai() {
+ return this.nai;
+ }
+ }
+
public ByteBuf serializeSubobject(final SrSubobject srSubobject) {
final ByteBuf buffer = Unpooled.buffer(MINIMAL_LENGTH);
// sid type
// nai
final Nai nai = srSubobject.getNai();
if (nai != null) {
- switch (srSubobject.getSidType()) {
- case Ipv4NodeId:
- writeIpv4Address(((IpNodeId) nai).getIpAddress().getIpv4Address(), buffer);
- break;
- case Ipv6NodeId:
- writeIpv6Address(((IpNodeId) nai).getIpAddress().getIpv6Address(), buffer);
- break;
- case Ipv4Adjacency:
- writeIpv4Address(((IpAdjacency) nai).getLocalIpAddress().getIpv4Address(), buffer);
- writeIpv4Address(((IpAdjacency) nai).getRemoteIpAddress().getIpv4Address(), buffer);
- break;
- case Ipv6Adjacency:
- writeIpv6Address(((IpAdjacency) nai).getLocalIpAddress().getIpv6Address(), buffer);
- writeIpv6Address(((IpAdjacency) nai).getRemoteIpAddress().getIpv6Address(), buffer);
- break;
- case Unnumbered:
- final UnnumberedAdjacency unnumbered = (UnnumberedAdjacency) nai;
- ByteBufWriteUtil.writeUnsignedInt(unnumbered.getLocalNodeId(), buffer);
- ByteBufWriteUtil.writeUnsignedInt(unnumbered.getLocalInterfaceId(), buffer);
- ByteBufWriteUtil.writeUnsignedInt(unnumbered.getRemoteNodeId(), buffer);
- ByteBufWriteUtil.writeUnsignedInt(unnumbered.getRemoteInterfaceId(), buffer);
- break;
- default:
- break;
- }
+ serializeNai(nai, srSubobject.getSidType() ,buffer);
}
return buffer;
}
+ private void serializeNai(final Nai nai, final SidType sidType, final ByteBuf buffer) {
+ switch (sidType) {
+ case Ipv4NodeId:
+ writeIpv4Address(((IpNodeId) nai).getIpAddress().getIpv4Address(), buffer);
+ break;
+ case Ipv6NodeId:
+ writeIpv6Address(((IpNodeId) nai).getIpAddress().getIpv6Address(), buffer);
+ break;
+ case Ipv4Adjacency:
+ writeIpv4Address(((IpAdjacency) nai).getLocalIpAddress().getIpv4Address(), buffer);
+ writeIpv4Address(((IpAdjacency) nai).getRemoteIpAddress().getIpv4Address(), buffer);
+ break;
+ case Ipv6Adjacency:
+ writeIpv6Address(((IpAdjacency) nai).getLocalIpAddress().getIpv6Address(), buffer);
+ writeIpv6Address(((IpAdjacency) nai).getRemoteIpAddress().getIpv6Address(), buffer);
+ break;
+ case Unnumbered:
+ final UnnumberedAdjacency unnumbered = (UnnumberedAdjacency) nai;
+ ByteBufWriteUtil.writeUnsignedInt(unnumbered.getLocalNodeId(), buffer);
+ ByteBufWriteUtil.writeUnsignedInt(unnumbered.getLocalInterfaceId(), buffer);
+ ByteBufWriteUtil.writeUnsignedInt(unnumbered.getRemoteNodeId(), buffer);
+ ByteBufWriteUtil.writeUnsignedInt(unnumbered.getRemoteInterfaceId(), buffer);
+ break;
+ default:
+ break;
+ }
+ }
+
+ private Nai parseNai(final SidType sidType, final ByteBuf buffer) {
+ switch (sidType) {
+ case Ipv4NodeId:
+ return new IpNodeIdBuilder().setIpAddress(
+ new IpAddress(new Ipv4Address(Ipv4Util.addressForByteBuf(buffer)))).build();
+ case Ipv6NodeId:
+ return new IpNodeIdBuilder().setIpAddress(
+ new IpAddress(Ipv6Util.addressForByteBuf(buffer))).build();
+ case Ipv4Adjacency:
+ return new IpAdjacencyBuilder()
+ .setLocalIpAddress(new IpAddress(Ipv4Util.addressForByteBuf(buffer)))
+ .setRemoteIpAddress(new IpAddress(Ipv4Util.addressForByteBuf(buffer))).build();
+ case Ipv6Adjacency:
+ return new IpAdjacencyBuilder()
+ .setLocalIpAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer)))
+ .setRemoteIpAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer))).build();
+ case Unnumbered:
+ return new UnnumberedAdjacencyBuilder().setLocalNodeId(buffer.readUnsignedInt())
+ .setLocalInterfaceId(buffer.readUnsignedInt()).setRemoteNodeId(buffer.readUnsignedInt())
+ .setRemoteInterfaceId(buffer.readUnsignedInt()).build();
+ default:
+ return null;
+ }
+ }
+
protected final SrSubobject parseSrSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
final int sidTypeByte = buffer.readByte() >> SID_TYPE_BITS_OFFSET;
final SidType sidType = SidType.forValue(sidTypeByte);
}
final Long sid = tmp;
final Nai nai;
-
if (sidType != null && !f) {
- switch (sidType) {
- case Ipv4NodeId:
- nai = new IpNodeIdBuilder().setIpAddress(
- new IpAddress(new Ipv4Address(Ipv4Util.addressForByteBuf(buffer)))).build();
- break;
- case Ipv6NodeId:
- nai = new IpNodeIdBuilder().setIpAddress(
- new IpAddress(Ipv6Util.addressForByteBuf(buffer))).build();
- break;
- case Ipv4Adjacency:
- nai = new IpAdjacencyBuilder()
- .setLocalIpAddress(new IpAddress(Ipv4Util.addressForByteBuf(buffer)))
- .setRemoteIpAddress(new IpAddress(Ipv4Util.addressForByteBuf(buffer))).build();
- break;
- case Ipv6Adjacency:
- nai = new IpAdjacencyBuilder()
- .setLocalIpAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer)))
- .setRemoteIpAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer))).build();
- break;
- case Unnumbered:
- nai = new UnnumberedAdjacencyBuilder().setLocalNodeId(buffer.readUnsignedInt())
- .setLocalInterfaceId(buffer.readUnsignedInt()).setRemoteNodeId(buffer.readUnsignedInt())
- .setRemoteInterfaceId(buffer.readUnsignedInt()).build();
- break;
- default:
- nai = null;
- break;
- }
+ nai = parseNai(sidType, buffer);
} else {
nai = null;
}
- return new SrSubobject() {
-
- @Override
- public Class<? extends DataContainer> getImplementedInterface() {
- return SrSubobject.class;
- }
-
- @Override
- public Boolean isMFlag() {
- return m;
- }
-
- @Override
- public Boolean isCFlag() {
- return c;
- }
-
- @Override
- public SidType getSidType() {
- return sidType;
- }
-
- @Override
- public Long getSid() {
- return sid;
- }
-
- @Override
- public Nai getNai() {
- return nai;
- }
- };
+ return new SrSubobjectImpl(m, c, sidType, sid, nai);
}
}