Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / AbstractPCEPSessionNegotiator.java
index 58cfdf5fe4d6b14a3ff1e25b4712b4089da67a48..ca80fc3e472f1f3a9de544294a46dcfa5600484e 100644 (file)
@@ -20,18 +20,18 @@ import javax.annotation.concurrent.GuardedBy;
 
 import org.opendaylight.protocol.framework.AbstractSessionNegotiator;
 import org.opendaylight.protocol.pcep.PCEPErrors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.pcerr.pcerr.message.error.type.Session;
+import org.opendaylight.protocol.pcep.message.PCEPErrorMessage;
+import org.opendaylight.protocol.pcep.message.PCEPOpenMessage;
+import org.opendaylight.protocol.pcep.object.PCEPErrorObject;
+import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.KeepaliveMessage;
 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.OpenMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenObject;
-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.keepalive.message.KeepaliveMessageBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessageBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
 
 /**
  * Abstract PCEP session negotiator. Takes care of basic handshake without implementing a specific policy. Policies need
@@ -70,7 +70,6 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
        }
 
        private static final Logger logger = LoggerFactory.getLogger(AbstractPCEPSessionNegotiator.class);
-
        private final Timer timer;
 
        @GuardedBy("this")
@@ -80,10 +79,10 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
        private Timeout failTimer;
 
        @GuardedBy("this")
-       private OpenObject localPrefs;
+       private PCEPOpenObject localPrefs;
 
        @GuardedBy("this")
-       private OpenObject remotePrefs;
+       private PCEPOpenObject remotePrefs;
 
        private volatile boolean localOK, openRetry, remoteOK;
 
@@ -97,7 +96,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
         * 
         * @return Session parameters proposal.
         */
-       protected abstract OpenObject getInitialProposal();
+       protected abstract PCEPOpenObject getInitialProposal();
 
        /**
         * Get the revised session parameters proposal based on the feedback the peer has provided to us.
@@ -105,7 +104,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
         * @param suggestion Peer-provided suggested session parameters
         * @return Session parameters proposal.
         */
-       protected abstract OpenObject getRevisedProposal(OpenObject suggestion);
+       protected abstract PCEPOpenObject getRevisedProposal(PCEPOpenObject suggestion);
 
        /**
         * Check whether a peer-provided session parameters proposal is acceptable.
@@ -113,7 +112,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
         * @param proposal peer-proposed session parameters
         * @return true if the proposal is acceptable, false otherwise
         */
-       protected abstract boolean isProposalAcceptable(OpenObject proposal);
+       protected abstract boolean isProposalAcceptable(PCEPOpenObject proposal);
 
        /**
         * Given a peer-provided session parameters proposal which we found unacceptable, provide a counter-proposal. The
@@ -122,7 +121,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
         * @param proposal unacceptable peer proposal
         * @return our counter-proposal, or null if there is no way to negotiate an acceptable proposal
         */
-       protected abstract OpenObject getCounterProposal(OpenObject proposal);
+       protected abstract PCEPOpenObject getCounterProposal(PCEPOpenObject proposal);
 
        /**
         * Create the protocol session.
@@ -134,7 +133,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
         * @param remotePrefs Session preferences proposed by the peer and accepted by us.
         * @return New protocol session.
         */
-       protected abstract PCEPSessionImpl createSession(Timer timer, Channel channel, OpenObject localPrefs, OpenObject remotePrefs);
+       protected abstract PCEPSessionImpl createSession(Timer timer, Channel channel, PCEPOpenObject localPrefs, PCEPOpenObject remotePrefs);
 
        /**
         * Sends PCEP Error Message with one PCEPError.
@@ -142,8 +141,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
         * @param value
         */
        private void sendErrorMessage(final PCEPErrors value) {
-
-               this.channel.writeAndFlush(Util.createErrorMessage(value, null));
+               this.channel.writeAndFlush(new PCEPErrorMessage(ImmutableList.of(new PCEPErrorObject(value))));
        }
 
        private void scheduleFailTimer() {
@@ -181,10 +179,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
        final synchronized protected void startNegotiation() {
                Preconditions.checkState(this.state == State.Idle);
                this.localPrefs = getInitialProposal();
-               final OpenMessage m = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.OpenBuilder().setOpenMessage(
-                               new OpenMessageBuilder().setOpen(
-                                               (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.open.message.Open) this.localPrefs).build()).build();
-               this.channel.writeAndFlush(m);
+               this.channel.writeAndFlush(new PCEPOpenMessage(this.localPrefs));
                this.state = State.OpenWait;
                scheduleFailTimer();
 
@@ -214,9 +209,9 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
                                }
 
                                return;
-                       } else if (msg instanceof PcerrMessage) {
-                               final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessage err = ((PcerrMessage) msg).getPcerrMessage();
-                               this.localPrefs = getRevisedProposal((OpenObject) ((Session) err.getErrorType()).getOpen());
+                       } else if (msg instanceof PCEPErrorMessage) {
+                               final PCEPErrorMessage err = (PCEPErrorMessage) msg;
+                               this.localPrefs = getRevisedProposal(err.getOpenObject());
                                if (this.localPrefs == null) {
                                        sendErrorMessage(PCEPErrors.PCERR_NON_ACC_SESSION_CHAR);
                                        negotiationFailed(new RuntimeException("Peer suggested unacceptable retry proposal"));
@@ -233,9 +228,8 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
 
                        break;
                case OpenWait:
-                       if (msg instanceof OpenMessage) {
-                               final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessage o = ((OpenMessage) msg).getOpenMessage();
-                               final OpenObject open = o.getOpen();
+                       if (msg instanceof PCEPOpenMessage) {
+                               final PCEPOpenObject open = ((PCEPOpenMessage) msg).getOpenObject();
                                if (isProposalAcceptable(open)) {
                                        this.channel.writeAndFlush(new KeepaliveMessageBuilder().build());
                                        this.remotePrefs = open;
@@ -258,7 +252,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
                                        return;
                                }
 
-                               final OpenObject newPrefs = getCounterProposal(open);
+                               final PCEPOpenObject newPrefs = getCounterProposal(open);
                                if (newPrefs == null) {
                                        sendErrorMessage(PCEPErrors.NON_ACC_NON_NEG_SESSION_CHAR);
                                        negotiationFailed(new RuntimeException("Peer sent unacceptable session parameters"));
@@ -266,7 +260,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
                                        return;
                                }
 
-                               this.channel.writeAndFlush(Util.createErrorMessage(PCEPErrors.NON_ACC_NEG_SESSION_CHAR, newPrefs));
+                               this.channel.writeAndFlush(new PCEPErrorMessage(newPrefs, ImmutableList.of(new PCEPErrorObject(PCEPErrors.NON_ACC_NEG_SESSION_CHAR)), null));
 
                                this.openRetry = true;
                                this.state = this.localOK ? State.OpenWait : State.KeepWait;