/**
* Negotiation has not started yet.
*/
- Idle,
+ IDLE,
/**
* We have sent our Open message, and are waiting for the peer's Open message.
*/
- OpenSent,
+ OPEN_SENT,
/**
* We have received the peer's Open message, which is acceptable, and we're waiting the acknowledgement of our
* Open message.
*/
- OpenConfirm,
+ OPEN_CONFIRM,
/**
* The negotiation finished.
*/
- Finished,
+ FINISHED,
}
private static final Logger LOG = LoggerFactory.getLogger(AbstractBGPSessionNegotiator.class);
private final BGPSessionValidator sessionValidator;
@GuardedBy("this")
- private State state = State.Idle;
+ private State state = State.IDLE;
@GuardedBy("this")
private BGPSessionImpl session;
@Override
protected synchronized void startNegotiation() {
- Preconditions.checkState(this.state == State.Idle);
+ Preconditions.checkState(this.state == State.IDLE);
// Check if peer is configured in registry before retrieving preferences
if (!this.registry.isPeerConfigured(getRemoteIp())) {
}
this.sendMessage(new OpenBuilder().setMyAsNumber(as).setHoldTimer(preferences.getHoldTime()).setBgpIdentifier(
preferences.getBgpId()).setBgpParameters(preferences.getParams()).build());
- if (this.state != State.Finished) {
- this.state = State.OpenSent;
+ if (this.state != State.FINISHED) {
+ this.state = State.OPEN_SENT;
this.channel.eventLoop().schedule(new Runnable() {
@Override
public void run() {
- if (AbstractBGPSessionNegotiator.this.state != State.Finished) {
+ if (AbstractBGPSessionNegotiator.this.state != State.FINISHED) {
AbstractBGPSessionNegotiator.this.sendMessage(buildErrorNotify(BGPError.HOLD_TIMER_EXPIRED));
negotiationFailed(new BGPDocumentedException("HoldTimer expired", BGPError.FSM_ERROR));
- AbstractBGPSessionNegotiator.this.state = State.Finished;
+ AbstractBGPSessionNegotiator.this.state = State.FINISHED;
}
}
}, INITIAL_HOLDTIMER, TimeUnit.MINUTES);
LOG.debug("Channel {} handling message in state {}", this.channel, this.state);
switch (this.state) {
- case Finished:
- case Idle:
+ case FINISHED:
+ case IDLE:
this.sendMessage(buildErrorNotify(BGPError.FSM_ERROR));
return;
- case OpenConfirm:
+ case OPEN_CONFIRM:
if (msg instanceof Keepalive) {
negotiationSuccessful(this.session);
LOG.info("BGP Session with peer {} established successfully.", this.channel);
final Notify ntf = (Notify) msg;
negotiationFailed(new BGPDocumentedException("Peer refusal", BGPError.forValue(ntf.getErrorCode(), ntf.getErrorSubcode())));
}
- this.state = State.Finished;
+ this.state = State.FINISHED;
return;
- case OpenSent:
+ case OPEN_SENT:
if (msg instanceof Open) {
final Open openObj = (Open) msg;
handleOpen(openObj);
LOG.warn("Channel {} state {} unexpected message {}", this.channel, this.state, msg);
this.sendMessage(buildErrorNotify(BGPError.FSM_ERROR));
negotiationFailed(new BGPDocumentedException("Unexpected message", BGPError.FSM_ERROR));
- this.state = State.Finished;
+ this.state = State.FINISHED;
}
private static Notify buildErrorNotify(final BGPError err) {
final BGPSessionListener peer = this.registry.getPeer(getRemoteIp(), getSourceId(openObj, getPreferences()), getDestinationId(openObj, getPreferences()));
this.sendMessage(new KeepaliveBuilder().build());
this.session = new BGPSessionImpl(peer, this.channel, openObj, getPreferences());
- this.state = State.OpenConfirm;
+ this.state = State.OPEN_CONFIRM;
LOG.debug("Channel {} moved to OpenConfirm state with remote proposal {}", this.channel, openObj);
} catch (final BGPDocumentedException e) {
LOG.warn("Channel {} negotiation failed", this.channel, e);
}
this.registry.removePeerSession(getRemoteIp());
super.negotiationFailed(e);
- this.state = State.Finished;
+ this.state = State.FINISHED;
}
/**
* is half-alive, e.g. the timers are running, but the session is not completely up, e.g. it has not been
* announced to the listener. If the session is torn down in this state, we do not inform the listener.
*/
- OpenConfirm,
+ OPEN_CONFIRM,
/**
* The session has been completely established.
*/
- Up,
+ UP,
/**
* The session has been closed. It will not be resurrected.
*/
- Idle,
+ IDLE,
}
/**
private final Channel channel;
@GuardedBy("this")
- private State state = State.OpenConfirm;
+ private State state = State.OPEN_CONFIRM;
private final Set<BgpTableType> tableTypes;
private final int holdTimerValue;
@Override
public synchronized void close() {
LOG.info("Closing session: {}", this);
- if (this.state != State.Idle) {
+ if (this.state != State.IDLE) {
this.sendMessage(new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).setErrorSubcode(
BGPError.CEASE.getSubcode()).build());
this.channel.close();
- this.state = State.Idle;
+ this.state = State.IDLE;
}
}
@Override
public synchronized void endOfInput() {
- if (this.state == State.Up) {
+ if (this.state == State.UP) {
this.listener.onSessionDown(this, new IOException("End of input detected. Close the session."));
}
}
private synchronized void closeWithoutMessage() {
LOG.debug("Closing session: {}", this);
this.channel.close();
- this.state = State.Idle;
+ this.state = State.IDLE;
}
/**
* state will become IDLE), then rescheduling won't occur.
*/
private synchronized void handleHoldTimer() {
- if (this.state == State.Idle) {
+ if (this.state == State.IDLE) {
return;
}
* starts to execute (the session state will become IDLE), that rescheduling won't occur.
*/
private synchronized void handleKeepaliveTimer() {
- if (this.state == State.Idle) {
+ if (this.state == State.IDLE) {
return;
}
@Override
protected synchronized void sessionUp() {
this.sessionStats.startSessionStopwatch();
- this.state = State.Up;
+ this.state = State.UP;
this.listener.onSessionUp(this);
}
public void testCreateClient() throws InterruptedException, ExecutionException {
final BGPSessionImpl session = this.dispatcher.createClient(ADDRESS, AS_NUMBER, this.registry, new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, TIMEOUT)).get();
Assert.assertTrue(this.sessionListener.up);
- Assert.assertEquals(BGPSessionImpl.State.Up, session.getState());
+ Assert.assertEquals(BGPSessionImpl.State.UP, session.getState());
Assert.assertEquals(AS_NUMBER, session.getAsNumber());
Assert.assertEquals(IPV4, session.getBgpId());
Assert.assertEquals(Sets.newHashSet(this.ipv4tt), session.getAdvertisedTableTypes());
doReturn(this.eventLoop).when(this.speakerListener).eventLoop();
doAnswer(new Answer<Void>() {
@Override
- public Void answer(InvocationOnMock invocation) throws Throwable {
+ public Void answer(final InvocationOnMock invocation) throws Throwable {
final Runnable command = (Runnable) invocation.getArguments()[0];
final long delay = (long) invocation.getArguments()[1];
final TimeUnit unit = (TimeUnit) invocation.getArguments()[2];
@Test
public void testBGPSession() {
this.bgpSession.sessionUp();
- assertEquals(BGPSessionImpl.State.Up, this.bgpSession.getState());
+ assertEquals(BGPSessionImpl.State.UP, this.bgpSession.getState());
assertEquals(AS_NUMBER, this.bgpSession.getAsNumber());
assertEquals(BGP_ID, this.bgpSession.getBgpId());
assertEquals(1, this.bgpSession.getAdvertisedTableTypes().size());
assertTrue(this.listener.up);
//test stats
- BgpSessionState state = this.bgpSession.getBgpSesionState();
+ final BgpSessionState state = this.bgpSession.getBgpSesionState();
assertEquals(HOLD_TIMER, state.getHoldtimeCurrent().intValue());
assertEquals(1, state.getKeepaliveCurrent().intValue());
- assertEquals("Up", state.getSessionState());
+ assertEquals(BGPSessionImpl.State.UP.name(), state.getSessionState());
assertEquals(BGP_ID.getValue(), state.getPeerPreferences().getAddress());
assertEquals(AS_NUMBER.getValue(), state.getPeerPreferences().getAs());
assertEquals(BGP_ID.getValue(), state.getPeerPreferences().getBgpId());
assertEquals(0, state.getMessagesStats().getKeepAliveMsgs().getSent().getCount().longValue());
this.bgpSession.close();
- assertEquals(BGPSessionImpl.State.Idle, this.bgpSession.getState());
+ assertEquals(BGPSessionImpl.State.IDLE, this.bgpSession.getState());
assertEquals(1, this.receivedMsgs.size());
assertTrue(this.receivedMsgs.get(0) instanceof Notify);
final Notify error = (Notify) this.receivedMsgs.get(0);
@Test
public void testHandleOpenMsg() {
this.bgpSession.handleMessage(this.classicOpen);
- Assert.assertEquals(BGPSessionImpl.State.Idle, this.bgpSession.getState());
+ Assert.assertEquals(BGPSessionImpl.State.IDLE, this.bgpSession.getState());
Assert.assertEquals(1, this.receivedMsgs.size());
Assert.assertTrue(this.receivedMsgs.get(0) instanceof Notify);
final Notify error = (Notify) this.receivedMsgs.get(0);
assertEquals(1, this.bgpSession.getBgpSesionState().getMessagesStats().getErrorMsgs().getErrorReceived().getCount().longValue());
assertEquals(BGPError.BAD_BGP_ID.getCode(), this.bgpSession.getBgpSesionState().getMessagesStats().getErrorMsgs().getErrorReceived().getCode().shortValue());
assertEquals(BGPError.BAD_BGP_ID.getSubcode(), this.bgpSession.getBgpSesionState().getMessagesStats().getErrorMsgs().getErrorReceived().getSubCode().shortValue());
- Assert.assertEquals(BGPSessionImpl.State.Idle, this.bgpSession.getState());
+ Assert.assertEquals(BGPSessionImpl.State.IDLE, this.bgpSession.getState());
Mockito.verify(this.speakerListener).close();
}
public void testHoldTimerExpire() throws InterruptedException {
this.bgpSession.sessionUp();
Thread.sleep(3500);
- Assert.assertEquals(BGPSessionImpl.State.Idle, this.bgpSession.getState());
+ Assert.assertEquals(BGPSessionImpl.State.IDLE, this.bgpSession.getState());
Assert.assertEquals(3, this.receivedMsgs.size());
Assert.assertTrue(this.receivedMsgs.get(2) instanceof Notify);
final Notify error = (Notify) this.receivedMsgs.get(2);
assertEquals(2, this.receivedMsgs.size());
assertTrue(this.receivedMsgs.get(1) instanceof Keepalive);
this.clientSession.handleMessage(new KeepaliveBuilder().build());
- assertEquals(this.clientSession.getState(), BGPClientSessionNegotiator.State.Finished);
+ assertEquals(this.clientSession.getState(), BGPClientSessionNegotiator.State.FINISHED);
Thread.sleep(1000);
Thread.sleep(100);
}
this.clientSession.channelActive(null);
this.clientSession.handleMessage(this.classicOpen);
this.clientSession.handleMessage(new KeepaliveBuilder().build());
- assertEquals(this.clientSession.getState(), BGPClientSessionNegotiator.State.Finished);
+ assertEquals(this.clientSession.getState(), BGPClientSessionNegotiator.State.FINISHED);
this.clientSession.handleMessage(new OpenBuilder().setMyAsNumber(30).setHoldTimer(3).setVersion(new ProtocolVersion((short) 4)).build());
assertEquals(3, this.receivedMsgs.size());
assertTrue(this.receivedMsgs.get(2) instanceof Notify);
import java.util.Map;
public enum TerminationReason {
- Unknown((short) 1), ExpDeadtimer((short) 2), MalformedMsg((short) 3), TooManyUnknownReqRep((short) 4), TooManyUnknownMsg((short) 5);
+ UNKNOWN((short) 1), EXP_DEADTIMER((short) 2), MALFORMED_MSG((short) 3), TOO_MANY_UNKNWN_REQS((short) 4), TOO_MANY_UNKNOWN_MSGS((short) 5);
private short value;
private static final Map<Short, TerminationReason> VALUE_MAP;
final List<Metrics> metrics = Lists.newArrayList();
Object obj;
- State state = State.Init;
- while (!objects.isEmpty() && !state.equals(State.End)) {
+ State state = State.INIT;
+ while (!objects.isEmpty() && !state.equals(State.END)) {
obj = objects.get(0);
switch (state) {
- case Init:
- state = State.EroIn;
+ case INIT:
+ state = State.ERO_IN;
if (obj instanceof Ero) {
builder.setEro((Ero) obj);
break;
}
- case EroIn:
- state = State.BandwidthIn;
+ case ERO_IN:
+ state = State.BANDWIDTH_IN;
if (obj instanceof Bandwidth) {
builder.setBandwidth((Bandwidth) obj);
break;
}
- case BandwidthIn:
- state = State.MetricIn;
+ case BANDWIDTH_IN:
+ state = State.METRIC_IN;
if (obj instanceof Metric) {
metrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
- state = State.BandwidthIn;
+ state = State.BANDWIDTH_IN;
break;
}
- case MetricIn:
- state = State.End;
+ case METRIC_IN:
+ state = State.END;
break;
- case End:
+ case END:
break;
}
- if (!state.equals(State.End)) {
+ if (!state.equals(State.END)) {
objects.remove(0);
}
}
}
private enum State {
- Init, EroIn, BandwidthIn, MetricIn, End
+ INIT, ERO_IN, BANDWIDTH_IN, METRIC_IN, END
}
}
final List<Metrics> metrics = Lists.newArrayList();
Object obj;
- State state = State.Init;
- while (!objects.isEmpty() && !state.equals(State.End)) {
+ State state = State.INIT;
+ while (!objects.isEmpty() && !state.equals(State.END)) {
obj = objects.get(0);
switch (state) {
- case Init:
- state = State.EndpointsIn;
+ case INIT:
+ state = State.ENDPOINTS_IN;
if (obj instanceof EndpointsObj) {
builder.setEndpointsObj((EndpointsObj) obj);
break;
}
- case EndpointsIn:
- state = State.EroIn;
+ case ENDPOINTS_IN:
+ state = State.ERO_IN;
if (obj instanceof Ero) {
builder.setEro((Ero) obj);
break;
}
- case EroIn:
- state = State.LspaIn;
+ case ERO_IN:
+ state = State.LSPA_IN;
if (obj instanceof Lspa) {
builder.setLspa((Lspa) obj);
break;
}
- case LspaIn:
- state = State.BandwidthIn;
+ case LSPA_IN:
+ state = State.BANDWIDTH_IN;
if (obj instanceof Bandwidth) {
builder.setBandwidth((Bandwidth) obj);
break;
}
- case BandwidthIn:
- state = State.MetricIn;
+ case BANDWIDTH_IN:
+ state = State.METRIC_IN;
if (obj instanceof Metric) {
metrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
- state = State.BandwidthIn;
+ state = State.BANDWIDTH_IN;
break;
}
- case MetricIn:
- state = State.IroIn;
+ case METRIC_IN:
+ state = State.IRO_IN;
if (obj instanceof Iro) {
builder.setIro((Iro) obj);
break;
}
- case IroIn:
- state = State.End;
+ case IRO_IN:
+ state = State.END;
break;
- case End:
+ case END:
break;
}
- if (!state.equals(State.End)) {
+ if (!state.equals(State.END)) {
objects.remove(0);
}
}
}
private enum State {
- Init, EndpointsIn, EroIn, LspaIn, BandwidthIn, MetricIn, IroIn, End
+ INIT, ENDPOINTS_IN, ERO_IN, LSPA_IN, BANDWIDTH_IN, METRIC_IN, IRO_IN, END
}
}
final List<Errors> errorObjects = new ArrayList<>();
final PcerrMessageBuilder b = new PcerrMessageBuilder();
Object obj = objects.get(0);
- State state = State.Init;
+ State state = State.INIT;
if (obj instanceof ErrorObject) {
final ErrorObject o = (ErrorObject) obj;
errorObjects.add(new ErrorsBuilder().setErrorObject(o).build());
- state = State.ErrorIn;
+ state = State.ERROR_IN;
} else if (obj instanceof Rp) {
final Rp o = (Rp) obj;
if (o.isProcessingRule()) {
return null;
}
requestParameters.add(new RpsBuilder().setRp(o).build());
- state = State.RpIn;
+ state = State.RP_IN;
} else if (obj instanceof Srp) {
final Srp s = (Srp) obj;
srps.add(new SrpsBuilder().setSrp(s).build());
- state = State.SrpIn;
+ state = State.SRP_IN;
}
- if (!state.equals(State.Init)) {
+ if (!state.equals(State.INIT)) {
objects.remove(0);
}
while (!objects.isEmpty()) {
return new PcerrBuilder().setPcerrMessage(b.setErrors(((UnknownObject) obj).getErrors()).build()).build();
}
switch (state) {
- case ErrorIn:
- state = State.Open;
+ case ERROR_IN:
+ state = State.OPEN;
if (obj instanceof ErrorObject) {
final ErrorObject o = (ErrorObject) obj;
errorObjects.add(new ErrorsBuilder().setErrorObject(o).build());
- state = State.ErrorIn;
+ state = State.ERROR_IN;
break;
}
- case RpIn:
- state = State.Error;
+ case RP_IN:
+ state = State.ERROR;
if (obj instanceof Rp) {
final Rp o = ((Rp) obj);
requestParameters.add(new RpsBuilder().setRp(o).build());
- state = State.RpIn;
+ state = State.RP_IN;
break;
}
- case SrpIn:
- state = State.Error;
+ case SRP_IN:
+ state = State.ERROR;
if (obj instanceof Srp) {
final Srp o = ((Srp) obj);
srps.add(new SrpsBuilder().setSrp(o).build());
- state = State.SrpIn;
+ state = State.SRP_IN;
break;
}
- case Open:
- state = State.OpenIn;
+ case OPEN:
+ state = State.OPEN_IN;
if (obj instanceof Open) {
b.setErrorType(new SessionCaseBuilder().setSession(new SessionBuilder().setOpen((Open) obj).build()).build());
break;
}
- case Error:
- state = State.OpenIn;
+ case ERROR:
+ state = State.OPEN_IN;
if (obj instanceof ErrorObject) {
final ErrorObject o = (ErrorObject) obj;
errorObjects.add(new ErrorsBuilder().setErrorObject(o).build());
- state = State.Error;
+ state = State.ERROR;
break;
}
- case OpenIn:
- state = State.End;
+ case OPEN_IN:
+ state = State.END;
break;
- case End:
+ case END:
break;
default:
break;
}
- if (!state.equals(State.End)) {
+ if (!state.equals(State.END)) {
objects.remove(0);
}
}
}
private enum State {
- Init, ErrorIn, RpIn, SrpIn, Open, Error, OpenIn, End
+ INIT, ERROR_IN, RP_IN, SRP_IN, OPEN, ERROR, OPEN_IN, END
}
}
private void parsePath(final List<Object> objects, final PathBuilder builder) {
final List<Metrics> pathMetrics = Lists.newArrayList();
Object obj;
- State state = State.Init;
- while (!objects.isEmpty() && !state.equals(State.End)) {
+ State state = State.INIT;
+ while (!objects.isEmpty() && !state.equals(State.END)) {
obj = objects.get(0);
switch (state) {
- case Init:
- state = State.LspaIn;
+ case INIT:
+ state = State.LSPA_IN;
if (obj instanceof Lspa) {
builder.setLspa((Lspa) obj);
break;
}
- case LspaIn:
- state = State.BandwidthIn;
+ case LSPA_IN:
+ state = State.BANDWIDTH_IN;
if (obj instanceof Bandwidth) {
builder.setBandwidth((Bandwidth) obj);
break;
}
- case BandwidthIn:
- state = State.MetricIn;
+ case BANDWIDTH_IN:
+ state = State.METRIC_IN;
if (obj instanceof Metric) {
pathMetrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
- state = State.BandwidthIn;
+ state = State.BANDWIDTH_IN;
break;
}
- case MetricIn:
- state = State.IroIn;
+ case METRIC_IN:
+ state = State.IRO_IN;
if (obj instanceof Iro) {
builder.setIro((Iro) obj);
break;
}
- case IroIn:
- state = State.RroIn;
+ case IRO_IN:
+ state = State.RRO_IN;
if (obj instanceof Rro) {
builder.setRro((Rro) obj);
break;
}
- case RroIn:
- state = State.End;
+ case RRO_IN:
+ state = State.END;
break;
- case End:
+ case END:
break;
}
- if (!state.equals(State.End)) {
+ if (!state.equals(State.END)) {
objects.remove(0);
}
}
}
private enum State {
- Init, LspaIn, BandwidthIn, MetricIn, IroIn, RroIn, End
+ INIT, LSPA_IN, BANDWIDTH_IN, METRIC_IN, IRO_IN, RRO_IN, END
}
}
private void parsePath(final List<Object> objects, final PathBuilder pBuilder) {
final List<Metrics> pathMetrics = Lists.newArrayList();
Object obj;
- State state = State.Init;
- while (!objects.isEmpty() && !state.equals(State.End)) {
+ State state = State.INIT;
+ while (!objects.isEmpty() && !state.equals(State.END)) {
obj = objects.get(0);
switch (state) {
- case Init:
- state = State.LspaIn;
+ case INIT:
+ state = State.LSPA_IN;
if (obj instanceof Lspa) {
pBuilder.setLspa((Lspa) obj);
break;
}
- case LspaIn:
- state = State.BandwidthIn;
+ case LSPA_IN:
+ state = State.BANDWIDTH_IN;
if (obj instanceof Bandwidth) {
pBuilder.setBandwidth((Bandwidth) obj);
break;
}
- case BandwidthIn:
- state = State.MetricIn;
+ case BANDWIDTH_IN:
+ state = State.METRIC_IN;
if (obj instanceof Metric) {
pathMetrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
- state = State.BandwidthIn;
+ state = State.BANDWIDTH_IN;
break;
}
- case MetricIn:
- state = State.IroIn;
+ case METRIC_IN:
+ state = State.IRO_IN;
if (obj instanceof Iro) {
pBuilder.setIro((Iro) obj);
break;
}
- case IroIn:
- state = State.End;
+ case IRO_IN:
+ state = State.END;
break;
- case End:
+ case END:
break;
}
- if (!state.equals(State.End)) {
+ if (!state.equals(State.END)) {
objects.remove(0);
}
}
}
private enum State {
- Init, LspaIn, BandwidthIn, MetricIn, IroIn, End
+ INIT, LSPA_IN, BANDWIDTH_IN, METRIC_IN, IRO_IN, END
}
}
* Negotiation has not begun. It will be activated once we are asked to provide our initial proposal, at which
* point we move into OpenWait state.
*/
- Idle,
+ IDLE,
/**
* Waiting for the peer's OPEN message.
*/
- OpenWait,
+ OPEN_WAIT,
/**
* Waiting for the peer's KEEPALIVE message.
*/
- KeepWait,
+ KEEP_WAIT,
/**
* Negotiation has completed.
*/
- Finished,
+ FINISHED,
}
private static final Logger LOG = LoggerFactory.getLogger(AbstractPCEPSessionNegotiator.class);
private static final Keepalive KEEPALIVE = new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build();
private volatile boolean localOK, openRetry, remoteOK;
- private volatile State state = State.Idle;
+ private volatile State state = State.IDLE;
private Future<?> failTimer;
private Open localPrefs;
private Open remotePrefs;
@Override
public void run() {
switch (AbstractPCEPSessionNegotiator.this.state) {
- case Finished:
- case Idle:
+ case FINISHED:
+ case IDLE:
break;
- case KeepWait:
+ case KEEP_WAIT:
sendErrorMessage(PCEPErrors.NO_MSG_BEFORE_EXP_KEEPWAIT);
negotiationFailed(new TimeoutException("KeepWait timer expired"));
- AbstractPCEPSessionNegotiator.this.state = State.Finished;
+ AbstractPCEPSessionNegotiator.this.state = State.FINISHED;
break;
- case OpenWait:
+ case OPEN_WAIT:
sendErrorMessage(PCEPErrors.NO_OPEN_BEFORE_EXP_OPENWAIT);
negotiationFailed(new TimeoutException("OpenWait timer expired"));
- AbstractPCEPSessionNegotiator.this.state = State.Finished;
+ AbstractPCEPSessionNegotiator.this.state = State.FINISHED;
break;
}
}
@Override
protected final void startNegotiation() {
- Preconditions.checkState(this.state == State.Idle);
+ 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(this.localPrefs).build()).build();
this.sendMessage(m);
- this.state = State.OpenWait;
+ this.state = State.OPEN_WAIT;
scheduleFailTimer();
LOG.info("PCEP session with {} started, sent proposal {}", this.channel, this.localPrefs);
if (this.remoteOK) {
LOG.info("PCEP peer {} completed negotiation", this.channel);
negotiationSuccessful(createSession(this.channel, this.localPrefs, this.remotePrefs));
- this.state = State.Finished;
+ this.state = State.FINISHED;
} else {
scheduleFailTimer();
- this.state = State.OpenWait;
+ this.state = State.OPEN_WAIT;
LOG.debug("Channel {} moved to OpenWait state with localOK=1", this.channel);
}
return true;
final ErrorObject obj = err.getErrors().get(0).getErrorObject();
LOG.warn("Unexpected error received from PCC: type {} value {}", obj.getType(), obj.getValue());
negotiationFailed(new IllegalStateException("Unexpected error received from PCC."));
- this.state = State.Idle;
+ this.state = State.IDLE;
return true;
}
this.localPrefs = getRevisedProposal(((SessionCase) err.getErrorType()).getSession().getOpen());
if (this.localPrefs == null) {
sendErrorMessage(PCEPErrors.PCERR_NON_ACC_SESSION_CHAR);
negotiationFailed(new IllegalStateException("Peer suggested unacceptable retry proposal"));
- this.state = State.Finished;
+ this.state = State.FINISHED;
return true;
}
this.sendMessage(new OpenBuilder().setOpenMessage(new OpenMessageBuilder().setOpen(this.localPrefs).build()).build());
if (!this.remoteOK) {
- this.state = State.OpenWait;
+ this.state = State.OPEN_WAIT;
}
scheduleFailTimer();
return true;
if (this.localOK) {
negotiationSuccessful(createSession(this.channel, this.localPrefs, this.remotePrefs));
LOG.info("PCEP peer {} completed negotiation", this.channel);
- this.state = State.Finished;
+ this.state = State.FINISHED;
} else {
scheduleFailTimer();
- this.state = State.KeepWait;
+ 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;
+ this.state = State.FINISHED;
return true;
}
if (newPrefs == null) {
sendErrorMessage(PCEPErrors.NON_ACC_NON_NEG_SESSION_CHAR);
negotiationFailed(new IllegalStateException("Peer sent unacceptable session parameters"));
- this.state = State.Finished;
+ 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.OpenWait : State.KeepWait;
+ this.state = this.localOK ? State.OPEN_WAIT : State.KEEP_WAIT;
scheduleFailTimer();
return true;
}
LOG.debug("Channel {} handling message {} in state {}", this.channel, msg, this.state);
switch (this.state) {
- case Finished:
- case Idle:
+ case FINISHED:
+ case IDLE:
throw new IllegalStateException("Unexpected handleMessage in state " + this.state);
- case KeepWait:
+ case KEEP_WAIT:
if (handleMessageKeepWait(msg)) {
return;
}
break;
- case OpenWait:
+ case OPEN_WAIT:
if (handleMessageOpenWait(msg)) {
return;
}
LOG.warn("Channel {} in state {} received unexpected message {}", this.channel, this.state, msg);
sendErrorMessage(PCEPErrors.NON_OR_INVALID_OPEN_MSG);
negotiationFailed(new Exception("Illegal message encountered"));
- this.state = State.Finished;
+ this.state = State.FINISHED;
}
@VisibleForTesting
if (this.channel.isActive()) {
if (ct >= nextDead) {
LOG.debug("DeadTimer expired. {}", new Date());
- this.terminate(TerminationReason.ExpDeadtimer);
+ this.terminate(TerminationReason.EXP_DEADTIMER);
} else {
this.channel.eventLoop().schedule(new Runnable() {
@Override
this.unknownMessagesTimes.poll();
}
if (this.unknownMessagesTimes.size() > this.maxUnknownMessages) {
- this.terminate(TerminationReason.TooManyUnknownMsg);
+ this.terminate(TerminationReason.TOO_MANY_UNKNOWN_MSGS);
}
}
}
final PcerrMessageBuilder b = new PcerrMessageBuilder();
Object obj = objects.get(0);
- State state = State.Init;
+ State state = State.INIT;
if (obj instanceof ErrorObject) {
final ErrorObject o = (ErrorObject) obj;
errorObjects.add(new ErrorsBuilder().setErrorObject(o).build());
- state = State.ErrorIn;
+ state = State.ERROR_IN;
} else if (obj instanceof Rp) {
final Rp o = (Rp) obj;
if (o.isProcessingRule()) {
return null;
}
requestParameters.add(new RpsBuilder().setRp(o).build());
- state = State.RpIn;
+ state = State.RP_IN;
}
- if (state.equals(State.Init)) {
+ if (state.equals(State.INIT)) {
throw new PCEPDeserializerException("At least one PCEPErrorObject is mandatory.");
}
objects.remove(0);
return new PcerrBuilder().setPcerrMessage(b.setErrors(((UnknownObject) obj).getErrors()).build()).build();
}
switch (state) {
- case ErrorIn:
- state = State.Open;
+ case ERROR_IN:
+ state = State.OPEN;
if (obj instanceof ErrorObject) {
final ErrorObject o = (ErrorObject) obj;
errorObjects.add(new ErrorsBuilder().setErrorObject(o).build());
- state = State.ErrorIn;
+ state = State.ERROR_IN;
break;
}
- case RpIn:
- state = State.Error;
+ case RP_IN:
+ state = State.ERROR;
if (obj instanceof Rp) {
final Rp o = ((Rp) obj);
requestParameters.add(new RpsBuilder().setRp(o).build());
- state = State.RpIn;
+ state = State.RP_IN;
break;
}
- case Open:
- state = State.OpenIn;
+ case OPEN:
+ state = State.OPEN_IN;
if (obj instanceof Open) {
b.setErrorType(new SessionCaseBuilder().setSession(new SessionBuilder().setOpen((Open) obj).build()).build());
break;
}
- case Error:
- state = State.OpenIn;
+ case ERROR:
+ state = State.OPEN_IN;
if (obj instanceof ErrorObject) {
final ErrorObject o = (ErrorObject) obj;
errorObjects.add(new ErrorsBuilder().setErrorObject(o).build());
- state = State.Error;
+ state = State.ERROR;
break;
}
- case OpenIn:
- state = State.End;
+ case OPEN_IN:
+ state = State.END;
break;
- case End:
+ case END:
break;
default:
break;
}
- if (!state.equals(State.End)) {
+ if (!state.equals(State.END)) {
objects.remove(0);
}
}
}
private enum State {
- Init, ErrorIn, RpIn, Open, Error, OpenIn, End
+ INIT, ERROR_IN, RP_IN, OPEN, ERROR, OPEN_IN, END
}
}
final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.Notifications> notifications = new ArrayList<>();
Object obj;
- State state = State.Init;
- while (!objects.isEmpty() && !state.equals(State.End)) {
+ State state = State.INIT;
+ while (!objects.isEmpty() && !state.equals(State.END)) {
obj = objects.get(0);
switch (state) {
- case Init:
- state = State.RpIn;
+ case INIT:
+ state = State.RP_IN;
if (obj instanceof Rp) {
final Rp rp = (Rp) obj;
if (rp.isProcessingRule()) {
return null;
}
requestParameters.add(new RpsBuilder().setRp(rp).build());
- state = State.Init;
+ state = State.INIT;
break;
}
- case RpIn:
- state = State.NotificationIn;
+ case RP_IN:
+ state = State.NOTIFICATION_IN;
if (obj instanceof CNotification) {
final CNotification n = (CNotification) obj;
notifications.add(new NotificationsBuilder().setCNotification(n).build());
- state = State.RpIn;
+ state = State.RP_IN;
break;
}
- case NotificationIn:
- state = State.End;
+ case NOTIFICATION_IN:
+ state = State.END;
break;
- case End:
+ case END:
break;
}
- if (!state.equals(State.End)) {
+ if (!state.equals(State.END)) {
objects.remove(0);
}
}
}
private enum State {
- Init, RpIn, NotificationIn, End
+ INIT, RP_IN, NOTIFICATION_IN, END
}
}
final List<Metrics> pathMetrics = new ArrayList<>();
Object obj;
- State state = State.Init;
- while (!objects.isEmpty() && !state.equals(State.End)) {
+ State state = State.INIT;
+ while (!objects.isEmpty() && !state.equals(State.END)) {
obj = objects.get(0);
switch (state) {
- case Init:
- state = State.LspaIn;
+ case INIT:
+ state = State.LSPA_IN;
if (obj instanceof Lspa) {
builder.setLspa((Lspa) obj);
break;
}
- case LspaIn:
- state = State.BandwidthIn;
+ case LSPA_IN:
+ state = State.BANDWIDTH_IN;
if (obj instanceof Bandwidth) {
builder.setBandwidth((Bandwidth) obj);
break;
}
- case BandwidthIn:
- state = State.MetricIn;
+ case BANDWIDTH_IN:
+ state = State.METRIC_IN;
if (obj instanceof Metric) {
pathMetrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
- state = State.MetricIn;
+ state = State.METRIC_IN;
break;
}
- case MetricIn:
- state = State.IroIn;
+ case METRIC_IN:
+ state = State.IRO_IN;
if (obj instanceof Iro) {
builder.setIro((Iro) obj);
break;
}
- case IroIn:
- state = State.End;
+ case IRO_IN:
+ state = State.END;
break;
- case End:
+ case END:
break;
}
- if (!state.equals(State.End)) {
+ if (!state.equals(State.END)) {
objects.remove(0);
}
}
final List<Metrics> pathMetrics = new ArrayList<>();
Object obj;
- State state = State.Init;
- while (!objects.isEmpty() && !state.equals(State.End)) {
+ State state = State.INIT;
+ while (!objects.isEmpty() && !state.equals(State.END)) {
obj = objects.get(0);
switch (state) {
- case Init:
- state = State.LspaIn;
+ case INIT:
+ state = State.LSPA_IN;
if (obj instanceof Lspa) {
builder.setLspa((Lspa) obj);
break;
}
- case LspaIn:
- state = State.OfIn;
+ case LSPA_IN:
+ state = State.OF_IN;
if (obj instanceof Of) {
builder.setOf((Of) obj);
break;
}
- case OfIn:
- state = State.BandwidthIn;
+ case OF_IN:
+ state = State.BANDWIDTH_IN;
if (obj instanceof Bandwidth) {
builder.setBandwidth((Bandwidth) obj);
break;
}
- case BandwidthIn:
- state = State.MetricIn;
+ case BANDWIDTH_IN:
+ state = State.METRIC_IN;
if (obj instanceof Metric) {
pathMetrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
- state = State.BandwidthIn;
+ state = State.BANDWIDTH_IN;
break;
}
- case MetricIn:
- state = State.IroIn;
+ case METRIC_IN:
+ state = State.IRO_IN;
if (obj instanceof Iro) {
builder.setIro((Iro) obj);
break;
}
- case IroIn:
- state = State.End;
+ case IRO_IN:
+ state = State.END;
break;
- case End:
+ case END:
break;
}
- if (!state.equals(State.End)) {
+ if (!state.equals(State.END)) {
objects.remove(0);
}
}
}
private enum State {
- Init, LspaIn, OfIn, BandwidthIn, MetricIn, IroIn, End
+ INIT, LSPA_IN, OF_IN, BANDWIDTH_IN, METRIC_IN, IRO_IN, END
}
}
final List<Metrics> metrics = new ArrayList<>();
final List<VendorInformationObject> viObjects = new ArrayList<>();
- State state = State.Init;
- while (!objects.isEmpty() && state != State.End) {
+ State state = State.INIT;
+ while (!objects.isEmpty() && state != State.END) {
Object obj = objects.get(0);
switch (state) {
- case Init:
- state = State.ReportedIn;
+ case INIT:
+ state = State.REPORTED_IN;
if (obj instanceof Rro) {
final ReportedRouteBuilder rrBuilder = new ReportedRouteBuilder();
rrBuilder.setRro((Rro) obj);
}
break;
}
- case ReportedIn:
- state = State.VendorInfoList;
+ case REPORTED_IN:
+ state = State.VENDOR_INFO_LIST;
if (obj instanceof VendorInformationObject) {
viObjects.add((VendorInformationObject) obj);
- state = State.ReportedIn;
+ state = State.REPORTED_IN;
break;
}
- case VendorInfoList:
- state = State.LoadBIn;
+ case VENDOR_INFO_LIST:
+ state = State.LOAD_BIN;
if (obj instanceof LoadBalancing) {
builder.setLoadBalancing((LoadBalancing) obj);
break;
}
- case LoadBIn:
- state = State.LspaIn;
+ case LOAD_BIN:
+ state = State.LSPA_IN;
if (obj instanceof Lspa) {
builder.setLspa((Lspa) obj);
break;
}
- case LspaIn:
- state = State.BandwidthIn;
+ case LSPA_IN:
+ state = State.BANDWIDTH_IN;
if (obj instanceof Bandwidth) {
builder.setBandwidth((Bandwidth) obj);
break;
}
- case BandwidthIn:
- state = State.MetricIn;
+ case BANDWIDTH_IN:
+ state = State.METRIC_IN;
if (obj instanceof Metric) {
metrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
- state = State.BandwidthIn;
+ state = State.BANDWIDTH_IN;
break;
}
- case MetricIn:
- state = State.IroIn;
+ case METRIC_IN:
+ state = State.IRO_IN;
if (obj instanceof Iro) {
builder.setIro((Iro) obj);
break;
}
- case IroIn:
- state = State.RroIn;
+ case IRO_IN:
+ state = State.RRO_IN;
if (obj instanceof Rro) {
builder.setRro((Rro) obj);
break;
}
- case RroIn:
- state = State.XroIn;
+ case RRO_IN:
+ state = State.XRO_IN;
if (obj instanceof Xro) {
builder.setXro((Xro) obj);
break;
}
- case XroIn:
- state = State.OfIn;
+ case XRO_IN:
+ state = State.OF_IN;
if (obj instanceof Of) {
builder.setOf((Of) obj);
break;
}
- case OfIn:
- state = State.CtIn;
+ case OF_IN:
+ state = State.CT_IN;
if (obj instanceof ClassType) {
final ClassType classType = (ClassType) obj;
if (!classType.isProcessingRule()) {
}
break;
}
- case CtIn:
- state = State.End;
+ case CT_IN:
+ state = State.END;
break;
- case End:
+ case END:
break;
}
- if (!state.equals(State.End)) {
+ if (!state.equals(State.END)) {
objects.remove(0);
}
}
}
private enum State {
- Init, ReportedIn, VendorInfoList, LoadBIn, LspaIn, BandwidthIn, MetricIn, IroIn, RroIn, XroIn, OfIn, CtIn, End
+ INIT, REPORTED_IN, VENDOR_INFO_LIST, LOAD_BIN, LSPA_IN, BANDWIDTH_IN, METRIC_IN, IRO_IN, RRO_IN, XRO_IN, OF_IN, CT_IN, END
}
private Svec getValidSvec(final SvecBuilder builder, final List<Object> objects) {
final List<VendorInformationObject> viObjects = new ArrayList<>();
Object obj = null;
- SvecState state = SvecState.Init;
- while (!objects.isEmpty() && !state.equals(SvecState.End)) {
+ SvecState state = SvecState.INIT;
+ while (!objects.isEmpty() && !state.equals(SvecState.END)) {
obj = objects.get(0);
switch (state) {
- case Init:
- state = SvecState.OfIn;
+ case INIT:
+ state = SvecState.OF_IN;
if (obj instanceof Of) {
builder.setOf((Of) obj);
break;
}
- case OfIn:
- state = SvecState.GcIn;
+ case OF_IN:
+ state = SvecState.GC_IN;
if (obj instanceof Gc) {
builder.setGc((Gc) obj);
break;
}
- case GcIn:
- state = SvecState.XroIn;
+ case GC_IN:
+ state = SvecState.XRO_IN;
if (obj instanceof Xro) {
builder.setXro((Xro) obj);
break;
}
- case XroIn:
- state = SvecState.MetricIn;
+ case XRO_IN:
+ state = SvecState.METRIC_IN;
if (obj instanceof Metric) {
metrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
- state = SvecState.XroIn;
+ state = SvecState.XRO_IN;
break;
}
- case MetricIn:
- state = SvecState.VendorInfo;
+ case METRIC_IN:
+ state = SvecState.VENDOR_INFO;
if (obj instanceof VendorInformationObject) {
viObjects.add((VendorInformationObject) obj);
- state = SvecState.MetricIn;
+ state = SvecState.METRIC_IN;
break;
}
- case VendorInfo:
- state = SvecState.End;
+ case VENDOR_INFO:
+ state = SvecState.END;
break;
- case End:
+ case END:
break;
}
- if (!state.equals(SvecState.End)) {
+ if (!state.equals(SvecState.END)) {
objects.remove(0);
}
}
}
private enum SvecState {
- Init, OfIn, GcIn, XroIn, MetricIn, VendorInfo, End
+ INIT, OF_IN, GC_IN, XRO_IN, METRIC_IN, VENDOR_INFO, END
}
}
assertEquals(2, this.msgsSend.size());
assertTrue(this.msgsSend.get(1) instanceof Keepalive);
this.serverSession.handleMessage(this.kaMsg);
- assertEquals(this.serverSession.getState(), DefaultPCEPSessionNegotiator.State.Finished);
+ assertEquals(this.serverSession.getState(), DefaultPCEPSessionNegotiator.State.FINISHED);
}
/**
assertEquals(3, this.msgsSend.size());
assertTrue(this.msgsSend.get(2) instanceof Open);
this.serverSession.handleMessage(this.kaMsg);
- assertEquals(this.serverSession.getState(), DefaultPCEPSessionNegotiator.State.Finished);
+ assertEquals(this.serverSession.getState(), DefaultPCEPSessionNegotiator.State.FINISHED);
}
/**
// exceeded max. unknown messages count - terminate session
Assert.assertTrue(this.msgsSend.get(1) instanceof CloseMessage);
final CloseMessage closeMsg = (CloseMessage) this.msgsSend.get(1);
- Assert.assertEquals(TerminationReason.TooManyUnknownMsg, TerminationReason.forValue(closeMsg.getCCloseMessage().getCClose().getReason()));
+ Assert.assertEquals(TerminationReason.TOO_MANY_UNKNOWN_MSGS, TerminationReason.forValue(closeMsg.getCCloseMessage().getCClose().getReason()));
Mockito.verify(this.channel, Mockito.times(1)).close();
}
@Test
public void testCloseSessionWithReason() {
- this.session.close(TerminationReason.Unknown);
+ this.session.close(TerminationReason.UNKNOWN);
Assert.assertEquals(1, this.msgsSend.size());
Assert.assertTrue(this.msgsSend.get(0) instanceof CloseMessage);
final CloseMessage closeMsg = (CloseMessage) this.msgsSend.get(0);
- Assert.assertEquals(TerminationReason.Unknown, TerminationReason.forValue(closeMsg.getCCloseMessage().getCClose().getReason()));
+ Assert.assertEquals(TerminationReason.UNKNOWN, TerminationReason.forValue(closeMsg.getCCloseMessage().getCClose().getReason()));
Mockito.verify(this.channel, Mockito.times(1)).close();
}
@Override
public void close() {
- this.client.onSessionTerminated(this, new PCEPCloseTermination(TerminationReason.Unknown));
+ this.client.onSessionTerminated(this, new PCEPCloseTermination(TerminationReason.UNKNOWN));
}
}
@Override
public void onFailure(final Throwable t) {
LOG.error("Failed to update internal state for session {}, terminating it", session, t);
- session.close(TerminationReason.Unknown);
+ session.close(TerminationReason.UNKNOWN);
}
});
public void onFailure(final Throwable t) {
LOG.error("Failed to update internal state for session {}, closing it", session, t);
ctx.notifyRequests();
- session.close(TerminationReason.Unknown);
+ session.close(TerminationReason.UNKNOWN);
}
});
}
public void close() {
unregister();
if (this.session != null) {
- this.session.close(TerminationReason.Unknown);
+ this.session.close(TerminationReason.UNKNOWN);
}
}
assertEquals(1, getTopology().get().getNode().size());
// node should be removed after termination
- this.listener.onSessionTerminated(this.session, new PCEPCloseTermination(TerminationReason.Unknown));
+ this.listener.onSessionTerminated(this.session, new PCEPCloseTermination(TerminationReason.UNKNOWN));
assertEquals(0, getTopology().get().getNode().size());
}