import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-import org.opendaylight.protocol.bgp.concepts.BGPTableType;
import org.opendaylight.protocol.bgp.parser.BGPError;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
-import org.opendaylight.protocol.bgp.parser.BGPParameter;
-import org.opendaylight.protocol.bgp.parser.message.BGPKeepAliveMessage;
-import org.opendaylight.protocol.bgp.parser.message.BGPNotificationMessage;
-import org.opendaylight.protocol.bgp.parser.message.BGPOpenMessage;
-import org.opendaylight.protocol.bgp.parser.parameter.MultiprotocolCapability;
+import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkstateAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkstateSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Keepalive;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.KeepaliveBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Notify;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Open;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.OpenBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.ProtocolVersion;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParametersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.MultiprotocolCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.multiprotocol._case.MultiprotocolCapabilityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
+import org.opendaylight.yangtools.yang.binding.Notification;
import com.google.common.collect.Lists;
@Mock
private ChannelPipeline pipeline;
- private final BGPTableType ipv4tt = new BGPTableType(BgpAddressFamily.Ipv4, BgpSubsequentAddressFamily.Unicast);
+ private final BgpTableType ipv4tt = new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
- private final BGPTableType linkstatett = new BGPTableType(BgpAddressFamily.Linkstate, BgpSubsequentAddressFamily.Linkstate);
+ private final BgpTableType linkstatett = new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
- private final List<BGPMessage> receivedMsgs = Lists.newArrayList();
+ private final List<Notification> receivedMsgs = Lists.newArrayList();
- private BGPOpenMessage classicOpen;
+ private Open classicOpen;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- final List<BGPParameter> tlvs = Lists.newArrayList();
- tlvs.add(new MultiprotocolCapability(this.ipv4tt));
- tlvs.add(new MultiprotocolCapability(this.linkstatett));
- final BGPSessionPreferences prefs = new BGPSessionPreferences(new AsNumber((long) 30), (short) 3, null, tlvs);
+ final List<BgpParameters> tlvs = Lists.newArrayList();
+
+ tlvs.add(new BgpParametersBuilder().setCParameters(
+ new MultiprotocolCaseBuilder().setMultiprotocolCapability(
+ new MultiprotocolCapabilityBuilder().setAfi(this.ipv4tt.getAfi()).setSafi(this.ipv4tt.getSafi()).build()).build()).build());
+ tlvs.add(new BgpParametersBuilder().setCParameters(
+ new MultiprotocolCaseBuilder().setMultiprotocolCapability(
+ new MultiprotocolCapabilityBuilder().setAfi(this.linkstatett.getAfi()).setSafi(this.linkstatett.getSafi()).build()).build()).build());
+ final BGPSessionPreferences prefs = new BGPSessionPreferences(30, (short) 3, null, tlvs);
this.clientSession = new BGPSessionNegotiator(new HashedWheelTimer(), new DefaultPromise<BGPSessionImpl>(GlobalEventExecutor.INSTANCE), this.speakerListener, prefs, new SimpleSessionListener());
doAnswer(new Answer<Object>() {
@Override
public Object answer(final InvocationOnMock invocation) {
final Object[] args = invocation.getArguments();
- FSMTest.this.receivedMsgs.add((BGPMessage) args[0]);
+ FSMTest.this.receivedMsgs.add((Notification) args[0]);
return null;
}
- }).when(this.speakerListener).writeAndFlush(any(BGPMessage.class));
+ }).when(this.speakerListener).writeAndFlush(any(Notification.class));
doReturn("TestingChannel").when(this.speakerListener).toString();
doReturn(this.pipeline).when(this.speakerListener).pipeline();
doReturn(this.pipeline).when(this.pipeline).replace(any(ChannelHandler.class), any(String.class), any(ChannelHandler.class));
doReturn(mock(ChannelFuture.class)).when(this.speakerListener).close();
- this.classicOpen = new BGPOpenMessage(new AsNumber((long) 30), (short) 3, null, tlvs);
+ this.classicOpen = new OpenBuilder().setMyAsNumber(30).setHoldTimer(3).setVersion(new ProtocolVersion((short) 4)).setBgpParameters(
+ tlvs).build();
}
@Test
public void testAccSessionChar() throws InterruptedException {
this.clientSession.channelActive(null);
assertEquals(1, this.receivedMsgs.size());
- assertTrue(this.receivedMsgs.get(0) instanceof BGPOpenMessage);
+ assertTrue(this.receivedMsgs.get(0) instanceof Open);
this.clientSession.handleMessage(this.classicOpen);
assertEquals(2, this.receivedMsgs.size());
- assertTrue(this.receivedMsgs.get(1) instanceof BGPKeepAliveMessage);
- this.clientSession.handleMessage(new BGPKeepAliveMessage());
+ assertTrue(this.receivedMsgs.get(1) instanceof Keepalive);
+ this.clientSession.handleMessage(new KeepaliveBuilder().build());
assertEquals(this.clientSession.getState(), BGPSessionNegotiator.State.Finished);
- // Thread.sleep(3 * 1000);
- // Thread.sleep(100);
- // assertEquals(3, this.receivedMsgs.size());
- // assertTrue(this.receivedMsgs.get(2) instanceof BGPKeepAliveMessage); // test of keepalive timer
- // this.clientSession.handleMessage(new BGPOpenMessage(new ASNumber(30), (short) 3, null, null));
- // assertEquals(4, this.receivedMsgs.size());
- // assertTrue(this.receivedMsgs.get(3) instanceof BGPNotificationMessage);
- // final BGPMessage m = this.clientListener.getListMsg().get(3);
- // assertEquals(BGPError.FSM_ERROR, ((BGPNotificationMessage) m).getError());
+ Thread.sleep(1000);
+ Thread.sleep(100);
+ assertEquals(3, this.receivedMsgs.size());
+ assertTrue(this.receivedMsgs.get(2) instanceof Keepalive); // test of keepalive timer
}
@Test
public void testNotAccChars() throws InterruptedException {
this.clientSession.channelActive(null);
assertEquals(1, this.receivedMsgs.size());
- assertTrue(this.receivedMsgs.get(0) instanceof BGPOpenMessage);
- this.clientSession.handleMessage(new BGPOpenMessage(new AsNumber((long) 30), (short) 1, null, null));
+ assertTrue(this.receivedMsgs.get(0) instanceof Open);
+ this.clientSession.handleMessage(new OpenBuilder().setMyAsNumber(30).setHoldTimer(1).setVersion(new ProtocolVersion((short) 4)).build());
assertEquals(2, this.receivedMsgs.size());
- assertTrue(this.receivedMsgs.get(1) instanceof BGPNotificationMessage);
- final BGPMessage m = this.receivedMsgs.get(this.receivedMsgs.size() - 1);
- assertEquals(BGPError.UNSPECIFIC_OPEN_ERROR, ((BGPNotificationMessage) m).getError());
+ assertTrue(this.receivedMsgs.get(1) instanceof Notify);
+ final Notification m = this.receivedMsgs.get(this.receivedMsgs.size() - 1);
+ assertEquals(BGPError.UNSPECIFIC_OPEN_ERROR, BGPError.forValue(((Notify) m).getErrorCode(), ((Notify) m).getErrorSubcode()));
}
@Test
public void testNoOpen() throws InterruptedException {
this.clientSession.channelActive(null);
assertEquals(1, this.receivedMsgs.size());
- assertTrue(this.receivedMsgs.get(0) instanceof BGPOpenMessage);
+ assertTrue(this.receivedMsgs.get(0) instanceof Open);
Thread.sleep(BGPSessionNegotiator.INITIAL_HOLDTIMER * 1000 * 60);
Thread.sleep(100);
- final BGPMessage m = this.receivedMsgs.get(this.receivedMsgs.size() - 1);
- assertEquals(BGPError.HOLD_TIMER_EXPIRED, ((BGPNotificationMessage) m).getError());
+ final Notification m = this.receivedMsgs.get(this.receivedMsgs.size() - 1);
+ assertEquals(BGPError.HOLD_TIMER_EXPIRED, BGPError.forValue(((Notify) m).getErrorCode(), ((Notify) m).getErrorSubcode()));
}
@Test
public void sendNotification() {
this.clientSession.channelActive(null);
this.clientSession.handleMessage(this.classicOpen);
- this.clientSession.handleMessage(new BGPKeepAliveMessage());
+ this.clientSession.handleMessage(new KeepaliveBuilder().build());
assertEquals(this.clientSession.getState(), BGPSessionNegotiator.State.Finished);
- try {
- this.clientSession.handleMessage(new BGPOpenMessage(new AsNumber((long) 30), (short) 3, null, null));
- fail("Exception should be thrown.");
- } catch (final IllegalStateException e) {
- assertEquals("Unexpected state Finished", e.getMessage());
- }
+ 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);
+ final Notification m = this.receivedMsgs.get(2);
+ assertEquals(BGPError.FSM_ERROR.getCode(), ((Notify) m).getErrorCode().shortValue());
+ assertEquals(BGPError.FSM_ERROR.getSubcode(), ((Notify) m).getErrorSubcode().shortValue());
}
@After