<type>test-jar</type>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-broker-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-broker-impl</artifactId>
+ <scope>test</scope>
+ <type>test-jar</type>
+ </dependency>
</dependencies>
<build>
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. 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.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import com.google.common.collect.Lists;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+import org.opendaylight.protocol.bgp.rib.DefaultRibReference;
+import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsIn;
+import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsTransaction;
+import org.opendaylight.protocol.bgp.rib.spi.BGPObjectComparator;
+import org.opendaylight.protocol.bgp.rib.spi.Peer;
+import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext;
+import org.opendaylight.protocol.bgp.rib.spi.RouteEncoder;
+import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
+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.update.PathAttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.DestinationIpv4CaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.DestinationIpv6CaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.destination.ipv4._case.DestinationIpv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.destination.ipv6._case.DestinationIpv6Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.BgpRib;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.RibId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Route;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.Rib;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.RibKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
+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.Ipv6AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+
+public class AdjacencyRIBsInTest extends AbstractDataBrokerTest {
+
+ private WriteTransaction trans;
+
+ private final DefaultRibReference rib = new DefaultRibReference(InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(new RibId("test"))).toInstance());
+
+ private final RIBActivator act = new RIBActivator();
+
+ private final RIBExtensionProviderContext ctx = new SimpleRIBExtensionProviderContext();
+
+ private AdjRIBsIn<?, ?> a1;
+
+ private RIBTables tables;
+
+ private final TablesKey ipv4key = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+
+ private final TablesKey ipv6key = new TablesKey(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class);
+
+ private final TablesKey linkstateKey = new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
+
+ @Mock
+ AdjRIBsTransaction adjTrans4;
+
+ @Mock
+ AdjRIBsTransaction adjTrans6;
+
+ @Mock
+ AdjRIBsTransaction adjTransLS;
+
+ @Mock
+ Peer peer;
+
+ @Mock
+ KeyedInstanceIdentifier<Tables, TablesKey> id;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ this.trans = getDataBroker().newWriteOnlyTransaction();
+ this.act.startRIBExtensionProvider(this.ctx);
+ this.tables = new RIBTables(this.ctx);
+ Mockito.doReturn(new BGPObjectComparator(new AsNumber(72L))).when(this.adjTrans4).comparator();
+ Mockito.doReturn(new BGPObjectComparator(new AsNumber(72L))).when(this.adjTrans6).comparator();
+ Mockito.doReturn(new BGPObjectComparator(new AsNumber(72L))).when(this.adjTransLS).comparator();
+ Mockito.doReturn("test").when(this.peer).toString();
+ Mockito.doNothing().when(this.adjTrans4).advertise(Mockito.any(RouteEncoder.class), Mockito.anyObject(), Mockito.any(InstanceIdentifier.class), Mockito.eq(this.peer), Mockito.any(Route.class));
+ Mockito.doNothing().when(this.adjTrans4).setUptodate(Mockito.any(InstanceIdentifier.class), Mockito.anyBoolean());
+ Mockito.doNothing().when(this.adjTrans6).advertise(Mockito.any(RouteEncoder.class), Mockito.anyObject(), Mockito.any(InstanceIdentifier.class), Mockito.eq(this.peer), Mockito.any(Route.class));
+ Mockito.doNothing().when(this.adjTrans6).setUptodate(Mockito.any(InstanceIdentifier.class), Mockito.anyBoolean());
+ Mockito.doNothing().when(this.adjTransLS).advertise(Mockito.any(RouteEncoder.class), Mockito.anyObject(), Mockito.any(InstanceIdentifier.class), Mockito.eq(this.peer), Mockito.any(Route.class));
+ Mockito.doNothing().when(this.adjTransLS).setUptodate(Mockito.any(InstanceIdentifier.class), Mockito.anyBoolean());
+ }
+
+ @Test
+ public void testRIBTables() {
+ this.a1 = this.tables.create(this.trans, this.rib, this.ipv4key);
+ assertNotNull(this.a1);
+ assertEquals(this.a1, this.tables.get(this.ipv4key));
+ }
+
+ @Test
+ public void testAddRoutes() {
+ this.a1 = this.tables.create(this.trans, this.rib, this.ipv4key);
+ assertNotNull(this.a1);
+ MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
+ mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
+ new DestinationIpv4CaseBuilder().setDestinationIpv4(new DestinationIpv4Builder().setIpv4Prefixes(
+ Lists.newArrayList(new Ipv4Prefix("127.0.0.1"))).build()).build()).build());
+ final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+ this.a1.addRoutes(this.adjTrans4, this.peer, mpBuilder.build(), paBuilder.build());
+ Mockito.verify(this.adjTrans4).advertise(Mockito.any(RouteEncoder.class), Mockito.anyObject(), Mockito.any(InstanceIdentifier.class), Mockito.eq(this.peer), Mockito.any(Route.class));
+
+ final AdjRIBsIn<?, ?> a2 = this.tables.create(this.trans, this.rib, this.ipv6key);
+ assertNotNull(a2);
+ mpBuilder = new MpReachNlriBuilder();
+ mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
+ new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(
+ Lists.newArrayList(new Ipv6Prefix("2001:db8:1:2::"))).build()).build()).build());
+ a2.addRoutes(this.adjTrans6, this.peer, mpBuilder.build(), paBuilder.build());
+ Mockito.verify(this.adjTrans6).advertise(Mockito.any(RouteEncoder.class), Mockito.anyObject(), Mockito.any(InstanceIdentifier.class), Mockito.eq(this.peer), Mockito.any(Route.class));
+
+ final AdjRIBsIn<?, ?> a3 = this.tables.create(this.trans, this.rib, this.linkstateKey);
+ assertNull(a3);
+ }
+
+ @After
+ public void tearDown() {
+ this.act.close();
+ }
+
+}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
+import java.util.HashMap;
+import java.util.Map;
import org.junit.Test;
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.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.types.rev130919.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
public class ApiTest {
@Test
- public void testBGPSessionPreferences() {
- final BGPSessionPreferences sp = new BGPSessionPreferences(new AsNumber(58L), (short) 5, null, null);
+ public void testBGPSessionProposalImpl() {
+ final Map<Class<? extends AddressFamily>, Class<? extends SubsequentAddressFamily>> map = new HashMap<>();
+ map.put(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
+
+ final BGPSessionProposalImpl proposal = new BGPSessionProposalImpl((short) 5, new AsNumber(58L), null, map);
+ final BGPSessionPreferences sp = proposal.getProposal();
assertNull(sp.getBgpId());
- assertEquals((short) 5, sp.getHoldTime());
- assertEquals(new AsNumber(58L), sp.getMyAs());
+ assertEquals(proposal.getHoldTimer(), sp.getHoldTime());
+ assertEquals(proposal.getAs(), sp.getMyAs());
+ assertNull(proposal.getBgpId());
+
}
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
import com.google.common.base.Optional;
+import com.google.common.collect.Lists;
import com.google.common.util.concurrent.CheckedFuture;
+import io.netty.channel.Channel;
+import io.netty.channel.EventLoop;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
+import java.util.concurrent.TimeUnit;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfNodeCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.node._case.IsisNodeBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder;
+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.OpenBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.UpdateBuilder;
+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.message.rev130919.update.NlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.WithdrawnRoutesBuilder;
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.rib.rev130925.ApplicationRibId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.BgpRib;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.BgpRibBuilder;
@Mock
Optional<Rib> o;
+ BGPSessionImpl session;
+
List<InstanceIdentifier<?>> routes;
- private final byte[] linkNlri = new byte[] { 0, 2, 0, (byte) 0x65, 2, 0, 0,
- 0, 0, 0, 0, 0, 1, 1, 0, 0, (byte) 0x1a,
- (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02, (byte) 0x01,
- (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06,
- (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x18,
- (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02, (byte) 0x01,
- (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x04,
- (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, 1, 2, 0, 8, 1, 2, 3, 4, 0x0a, 0x0b, 0x0c, 0x0d,
- (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14,
- (byte) 0xa0, (byte) 0x2a, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14, (byte) 0xa0, (byte) 0x28,
- 1, 7, 0, 2, 0, 3};
+ private BGPPeer classic;
+
+ @Mock
+ Channel channel;
+
+ @Mock
+ private EventLoop eventLoop;
+
+ private final byte[] linkNlri = new byte[] { 0, 2, 0, 0x65, 2, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, (byte) 0x1a,
+ 2, 0, 0, 4, 0, 0, 0, 0x48, 2, 1, 0, 4, 0x28, 0x28, 0x28, 0x28, 2, 3, 0, 6, 0, 0, 0, 0, 0, 0x42, 1, 1, 0, 0x18,
+ 2, 0, 0, 4, 0, 0, 0, 0x48, 2, 1, 0, 4, 0x28, 0x28, 0x28, 0x28, 2, 3, 0, 4, 0, 0, 0, 0x40, 1, 2, 0, 8, 1, 2, 3,
+ 4, 0x0a, 0x0b, 0x0c, 0x0d, 1, 3, 0, 4, (byte) 0xc5, 0x14, (byte) 0xa0, (byte) 0x2a, 1, 4, 0, 4, (byte) 0xc5,
+ 0x14, (byte) 0xa0, 0x28, 1, 7, 0, 2, 0, 3};
@SuppressWarnings("unchecked")
@Before
Mockito.doReturn(this.future).when(this.transWrite).submit();
Mockito.doNothing().when(this.future).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
Mockito.doReturn(this.transWrite).when(this.chain).newWriteOnlyTransaction();
+ Mockito.doReturn(this.eventLoop).when(this.channel).eventLoop();
Mockito.doAnswer(new Answer<Object>() {
@Override
assertEquals(1, this.routes.size());
}
+ @Test
+ public void testClassicPeer() {
+ this.classic = new BGPPeer("testPeer", this.r);
+ Mockito.doReturn(null).when(this.eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
+ Mockito.doReturn(Boolean.TRUE).when(this.channel).isWritable();
+ Mockito.doReturn(null).when(this.channel).close();
+ final List<BgpParameters> params = Lists.newArrayList(new BgpParametersBuilder().setCParameters(new MultiprotocolCaseBuilder()
+ .setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build()).build()).build());
+ this.session = new BGPSessionImpl(this.classic, this.channel, new OpenBuilder().setBgpIdentifier(new Ipv4Address("1.1.1.1")).setHoldTimer(50).setMyAsNumber(72).setBgpParameters(params).build(), 30);
+ assertEquals(this.r, this.classic.getRib());
+ assertEquals("testPeer", this.classic.getName());
+ Mockito.doAnswer(new Answer<Object>() {
+
+ @Override
+ public Object answer(final InvocationOnMock invocation) throws Throwable {
+ final Object[] args = invocation.getArguments();
+ ((SessionRIBsOut)args[0]).run();
+ return null;
+ }
+ }).when(this.eventLoop).submit(Mockito.any(Runnable.class));
+ this.classic.onSessionUp(this.session);
+ Assert.assertArrayEquals(new byte[] {1, 1, 1, 1}, this.classic.getRawIdentifier());
+ assertEquals("BGPPeer{name=testPeer, tables=[TablesKey [_afi=class org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily, _safi=class org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily]]}", this.classic.toString());
+ final List<Ipv4Prefix> prefs = Lists.newArrayList(new Ipv4Prefix("127.0.0.1/32"), new Ipv4Prefix("2.2.2.2/24"));
+ final UpdateBuilder ub = new UpdateBuilder();
+ ub.setNlri(new NlriBuilder().setNlri(prefs).build());
+ ub.setPathAttributes(new PathAttributesBuilder().build());
+ this.classic.onMessage(this.session, ub.build());
+ assertEquals(2, this.routes.size());
+
+ //create new peer so that it gets advertized routes from RIB
+ final BGPPeer testingPeer = new BGPPeer("testingPeer", this.r);
+ testingPeer.onSessionUp(this.session);
+ assertEquals(4, this.routes.size());
+
+ ub.setNlri(null);
+ ub.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setWithdrawnRoutes(prefs).build());
+ this.classic.onMessage(this.session, ub.build());
+ assertEquals(2, this.routes.size());
+ this.classic.onMessage(this.session, new KeepaliveBuilder().build());
+ this.classic.releaseConnection();
+ }
+
@Test
public void testClose() {
final AdjRIBsIn<Ipv4Prefix, Ipv4Route> a4 = this.r.getTable(this.tk);
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. 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.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
+import org.opendaylight.protocol.util.ByteArray;
+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;
+
+public class BGPParserTest {
+
+ private final MessageRegistry registry = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry();
+
+ @Test
+ public void testMessageToByteEncoding() {
+ final BGPMessageToByteEncoder encoder = new BGPMessageToByteEncoder(this.registry);
+ final ByteBuf out = Unpooled.buffer();
+ encoder.encode(null, new KeepaliveBuilder().build(), out);
+ assertArrayEquals(new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, 0, 0x13, 4}, ByteArray.readAllBytes(out));
+ }
+
+ @Test
+ public void testByteToMessageEncoding() throws Exception {
+ final BGPByteToMessageDecoder decoder = new BGPByteToMessageDecoder(this.registry);
+ final List<Object> out = new ArrayList<>();
+ decoder.decode(null, Unpooled.wrappedBuffer(new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, 0, 0x13, 4 }), out);
+ assertTrue(out.get(0) instanceof Keepalive);
+ decoder.decode(null, Unpooled.wrappedBuffer(new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, 0, 0x17, 3, 2, 4, 4, 9 }), out);
+ assertTrue(out.get(1) instanceof Notify);
+ }
+
+ @Test
+ public void testHandlerFactory() {
+ final BGPHandlerFactory handlers = new BGPHandlerFactory(this.registry);
+ assertEquals(1, handlers.getEncoders().length);
+ assertTrue(handlers.getEncoders()[0] instanceof BGPMessageToByteEncoder);
+ assertEquals(2, handlers.getDecoders().length);
+ assertTrue(handlers.getDecoders()[0] instanceof BGPMessageHeaderDecoder);
+ assertTrue(handlers.getDecoders()[1] instanceof BGPByteToMessageDecoder);
+ }
+}
tlvs).setBgpIdentifier(new Ipv4Address("1.1.1.2")).build();
}
+ @Test
+ public void testDenyPeer() {
+ this.clientSession = new BGPClientSessionNegotiator(new DefaultPromise<BGPSessionImpl>(GlobalEventExecutor.INSTANCE), this.speakerListener, new StrictBGPPeerRegistry(), new BGPClientSessionValidator(new AsNumber(30L)));
+ this.clientSession.channelActive(null);
+ assertEquals(1, this.receivedMsgs.size());
+ assertTrue(this.receivedMsgs.get(0) instanceof Notify);
+ }
+
@Test
public void testAccSessionChar() throws InterruptedException {
this.clientSession.channelActive(null);