* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.bgp.rib.impl;
import static java.util.Objects.requireNonNull;
private static final int INITIAL_HOLDTIMER = 4;
// <a href="http://tools.ietf.org/html/rfc6793">BGP Support for 4-Octet AS Number Space</a>
- private static final int AS_TRANS = 23456;
+ @VisibleForTesting
+ static final int AS_TRANS = 23456;
private static final Logger LOG = LoggerFactory.getLogger(AbstractBGPSessionNegotiator.class);
private final BGPPeerRegistry registry;
private final Promise<BGPSessionImpl> promise;
}
final BGPSessionPreferences preferences = this.registry.getPeerPreferences(remoteIp);
-
- int as = preferences.getMyAs().getValue().intValue();
- // Set as AS_TRANS if the value is bigger than 2B
- if (as > Values.UNSIGNED_SHORT_MAX_VALUE) {
- as = AS_TRANS;
- }
+ final int as = openASNumber(preferences.getMyAs().getValue().longValue());
sendMessage(new OpenBuilder().setMyAsNumber(as).setHoldTimer(preferences.getHoldTime()).setBgpIdentifier(
preferences.getBgpId()).setBgpParameters(preferences.getParams()).build());
if (this.state != State.FINISHED) {
LOG.info("Unexpected error during negotiation", cause);
negotiationFailedCloseChannel(cause);
}
+
+ @VisibleForTesting
+ static int openASNumber(final long configuredASNumber) {
+ // Return AS_TRANS if the value is bigger than 2B.
+ return configuredASNumber > Values.UNSIGNED_SHORT_MAX_VALUE ? AS_TRANS : (int) configuredASNumber;
+ }
}
--- /dev/null
+/*
+ * Copyright (c) 2019 Pantheon Technologies, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.rib.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.opendaylight.protocol.bgp.rib.impl.AbstractBGPSessionNegotiator.AS_TRANS;
+import static org.opendaylight.protocol.bgp.rib.impl.AbstractBGPSessionNegotiator.openASNumber;
+
+import org.junit.Test;
+
+public class AbstractBGPSessionNegotiatorTest {
+ @Test
+ public void testOpenASNumber() {
+ assertEquals(0, openASNumber(0));
+ assertEquals(65535, openASNumber(65535));
+ assertEquals(AS_TRANS, openASNumber(65536));
+ assertEquals(AS_TRANS, openASNumber(Integer.MAX_VALUE));
+ assertEquals(AS_TRANS, openASNumber(2147483648L));
+ assertEquals(AS_TRANS, openASNumber(4294967295L));
+ }
+}