Merge "Simplified inheritance within stateful module."
authorRobert Varga <nite@hq.sk>
Tue, 31 Mar 2015 14:47:01 +0000 (14:47 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 31 Mar 2015 14:47:02 +0000 (14:47 +0000)
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RIBImpl.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionNegotiator.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/Util.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPMonitoringReplyMessageParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPReplyMessageParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageParser.java
pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/AbstractSrSubobjectParser.java

index 53f183b892c26a9dc8625c2b7aa65a4f07c024ca..8b25aea06f5f2f74407fa3be09e884a2295b2ff2 100644 (file)
@@ -77,6 +77,7 @@ final class EffectiveRibInWriter implements AutoCloseable {
         }
 
         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.
@@ -190,6 +191,7 @@ final class EffectiveRibInWriter implements AutoCloseable {
 
         @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) {
index a4615e91a715f7faee35a781088a512427c732d7..ac3dd2e85c05192286e23773204a7b1fd45e1270 100644 (file)
@@ -127,7 +127,7 @@ public final class RIBImpl extends DefaultRibReference implements AutoCloseable,
     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;
@@ -168,13 +168,13 @@ public final class RIBImpl extends DefaultRibReference implements AutoCloseable,
 
     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);
@@ -191,18 +191,12 @@ public final class RIBImpl extends DefaultRibReference implements AutoCloseable,
 
         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(),
index 2b3f165f360432a2a479448a15d94fed4bd358ea..36f6289d63722cb6a5102996025cf36f2ac7ff56 100644 (file)
@@ -210,48 +210,44 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
     }
 
     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
index edeb1f615a6fe35c5c67301f0568ab191bfcca60..f32527ec99e53f9a3db340dc5297fc9b54964c35 100644 (file)
@@ -8,10 +8,17 @@
 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;
@@ -19,6 +26,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 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
@@ -41,4 +49,46 @@ public final class Util {
                     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;
+    }
 }
index 1f9f942ed4b79571f35b7f75b4f7df37892a3206..e5b670af5d57389aa00997c98445eb5a09f4971f 100644 (file)
@@ -14,6 +14,7 @@ import io.netty.buffer.ByteBuf;
 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;
@@ -24,7 +25,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.mes
 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;
@@ -32,12 +32,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 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;
 
 /**
@@ -119,7 +116,7 @@ public class PCEPMonitoringReplyMessageParser extends AbstractMessageParser {
                 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);
@@ -136,47 +133,4 @@ public class PCEPMonitoringReplyMessageParser extends AbstractMessageParser {
         }
         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;
-    }
-
 }
index c6b9134eb3d21e7ecd1f71d8803024c584268158..12d41e572d640514d8c2777a1d04e41ac1cf6198 100644 (file)
@@ -13,6 +13,7 @@ import io.netty.buffer.ByteBuf;
 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;
@@ -31,10 +32,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 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;
@@ -49,7 +48,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 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;
 
@@ -90,36 +88,46 @@ public class PCEPReplyMessageParser extends AbstractMessageParser {
         }
         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) {
@@ -183,37 +191,15 @@ public class PCEPReplyMessageParser extends AbstractMessageParser {
         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()) {
@@ -225,6 +211,34 @@ public class PCEPReplyMessageParser extends AbstractMessageParser {
         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<>();
 
@@ -336,46 +350,4 @@ public class PCEPReplyMessageParser extends AbstractMessageParser {
     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;
-    }
 }
index a9c70613590a1cb2c038b5aa4a3a2c6e4d5576a7..c3832787ee6f95d1ef5d700311f8328c95c77943 100644 (file)
@@ -199,19 +199,18 @@ public class PCEPRequestMessageParser extends AbstractMessageParser {
         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);
@@ -221,7 +220,6 @@ public class PCEPRequestMessageParser extends AbstractMessageParser {
                 if (objects.get(0) instanceof PathKey) {
                     rBuilder.setPathKeyExpansion(new PathKeyExpansionBuilder().setPathKey((PathKey) objects.get(0)).build());
                 }
-                continue;
             }
 
             final P2pBuilder p2pBuilder = new P2pBuilder();
index c35fbfa86307765ab48f6272883e85966c7a72d2..27bbfda6374125e6d3a192564e7ca996eb000267 100644 (file)
@@ -38,6 +38,54 @@ public abstract class AbstractSrSubobjectParser   {
 
     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
@@ -66,35 +114,64 @@ public abstract class AbstractSrSubobjectParser   {
         // 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);
@@ -117,70 +194,11 @@ public abstract class AbstractSrSubobjectParser   {
         }
         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);
     }
 }