import java.io.IOException;
import java.net.InetSocketAddress;
+import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
+import java.util.List;
import java.util.Queue;
import java.util.concurrent.TimeUnit;
import org.opendaylight.protocol.pcep.PCEPErrors;
import org.opendaylight.protocol.pcep.PCEPSession;
import org.opendaylight.protocol.pcep.PCEPSessionListener;
-import org.opendaylight.protocol.pcep.TerminationReason;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.CloseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseMessage;
+import org.opendaylight.protocol.pcep.PCEPTlv;
+import org.opendaylight.protocol.pcep.message.PCEPCloseMessage;
+import org.opendaylight.protocol.pcep.message.PCEPErrorMessage;
+import org.opendaylight.protocol.pcep.message.PCEPOpenMessage;
+import org.opendaylight.protocol.pcep.object.PCEPCloseObject;
+import org.opendaylight.protocol.pcep.object.PCEPCloseObject.Reason;
+import org.opendaylight.protocol.pcep.object.PCEPErrorObject;
+import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
+import org.opendaylight.protocol.pcep.tlv.NodeIdentifierTlv;
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.close.message.CCloseMessageBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CCloseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.keepalive.message.KeepaliveMessageBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Open Object with session characteristics that were accepted by another PCE (sent from this session).
*/
- private final OpenObject localOpen;
+ private final PCEPOpenObject localOpen;
/**
* Open Object with session characteristics for this session (sent from another PCE).
*/
- private final OpenObject remoteOpen;
+ private final PCEPOpenObject remoteOpen;
private static final Logger logger = LoggerFactory.getLogger(PCEPSessionImpl.class);
private final KeepaliveMessage kaMessage = (KeepaliveMessage) new KeepaliveMessageBuilder().build();
PCEPSessionImpl(final Timer timer, final PCEPSessionListener listener, final int maxUnknownMessages, final Channel channel,
- final OpenObject localOpen, final OpenObject remoteOpen) {
+ final PCEPOpenObject localOpen, final PCEPOpenObject remoteOpen) {
this.listener = Preconditions.checkNotNull(listener);
this.stateTimer = Preconditions.checkNotNull(timer);
this.channel = Preconditions.checkNotNull(channel);
if (this.channel.isActive()) {
if (ct >= nextDead) {
logger.debug("DeadTimer expired. " + new Date());
- this.terminate(TerminationReason.ExpDeadtimer);
+ this.terminate(Reason.EXP_DEADTIMER);
} else {
this.stateTimer.newTimeout(new TimerTask() {
@Override
* inside the session or from the listener, therefore the parent of this session should be informed.
*/
@Override
- public synchronized void close(final TerminationReason reason) {
+ public synchronized void close(final PCEPCloseObject.Reason reason) {
logger.debug("Closing session: {}", this);
this.closed = true;
- this.sendMessage(new CloseBuilder().setCCloseMessage(
- new CCloseMessageBuilder().setCClose(new CCloseBuilder().setReason(reason.getShortValue()).build()).build()).build());
+ // FIXME: just to get rid of compilation errors
+ this.sendMessage((Message) new PCEPCloseMessage(new PCEPCloseObject(reason)));
this.channel.close();
}
- private synchronized void terminate(final TerminationReason reason) {
+ private synchronized void terminate(final PCEPCloseObject.Reason reason) {
this.listener.onSessionTerminated(this, new PCEPCloseTermination(reason));
this.closed = true;
- this.sendMessage(new CloseBuilder().setCCloseMessage(
- new CCloseMessageBuilder().setCClose(new CCloseBuilder().setReason(reason.getShortValue()).build()).build()).build());
+ // FIXME: just to get rid of compilation errors
+ this.sendMessage((Message) new PCEPCloseMessage(new PCEPCloseObject(reason)));
this.close();
}
* @param value
* @param open
*/
- private void sendErrorMessage(final PCEPErrors value, final OpenObject open) {
- this.sendMessage(Util.createErrorMessage(value, open));
+ private void sendErrorMessage(final PCEPErrors value, final PCEPOpenObject open) {
+ final PCEPErrorObject error = new PCEPErrorObject(value);
+ final List<PCEPErrorObject> errors = new ArrayList<PCEPErrorObject>();
+ errors.add(error);
+ // FIXME: just to get rid of compilation errors
+ this.sendMessage((Message) new PCEPErrorMessage(open, errors, null));
}
/**
this.unknownMessagesTimes.poll();
}
if (this.unknownMessagesTimes.size() > this.maxUnknownMessages) {
- this.terminate(TerminationReason.TooManyUnknownMsg);
+ this.terminate(Reason.TOO_MANY_UNKNOWN_MSG);
}
}
}
// Internal message handling. The user does not see these messages
if (msg instanceof KeepaliveMessage) {
// Do nothing, the timer has been already reset
- } else if (msg instanceof OpenMessage) {
+ } else if (msg instanceof PCEPOpenMessage) {
this.sendErrorMessage(PCEPErrors.ATTEMPT_2ND_SESSION);
- } else if (msg instanceof CloseMessage) {
+ } else if (msg instanceof PCEPCloseMessage) {
/*
* Session is up, we are reporting all messages to user. One notable
* exception is CLOSE message, which needs to be converted into a
@Override
public Integer getDeadTimerValue() {
- return new Integer(this.remoteOpen.getDeadTimer());
+ return this.remoteOpen.getDeadTimerValue();
}
@Override
public Integer getKeepAliveTimerValue() {
- return new Integer(this.localOpen.getKeepalive());
+ return this.localOpen.getKeepAliveTimerValue();
}
@Override
this.close();
}
+ @Override
+ public String getNodeIdentifier() {
+ for (final PCEPTlv tlv : this.remoteOpen.getTlvs()) {
+ if (tlv instanceof NodeIdentifierTlv) {
+ return tlv.toString();
+ }
+ }
+ return "";
+ }
+
@Override
public final String toString() {
return addToStringAttributes(Objects.toStringHelper(this)).toString();
protected void sessionUp() {
this.listener.onSessionUp(this);
}
-
- @Override
- public String getNodeIdentifier() {
- if (this.remoteOpen.getTlvs() == null)
- if (this.remoteOpen.getTlvs().getPredundancyGroupId() != null) {
- return new String(this.remoteOpen.getTlvs().getPredundancyGroupId().getIdentifier());
- }
- return "";
- }
-
}