public final class SimpleEvpnNlriRegistryTest {
public static final YangInstanceIdentifier.NodeIdentifier EVPN_NID = new YangInstanceIdentifier.NodeIdentifier(EvpnChoice.QNAME);
- private class notRegistered implements EvpnChoice {
+ private class NotRegistered implements EvpnChoice {
@Override
public Class<? extends DataContainer> getImplementedInterface() {
- return notRegistered.class;
+ return NotRegistered.class;
}
}
@Test
public void registryNullTest() {
final ByteBuf body = Unpooled.buffer();
- SimpleEvpnNlriRegistry.getInstance().serializeEvpn(new notRegistered(), body);
+ SimpleEvpnNlriRegistry.getInstance().serializeEvpn(new NotRegistered(), body);
assertEquals(0, body.readableBytes());
}
package org.opendaylight.protocol.bgp.openconfig.impl;
import static org.opendaylight.protocol.bgp.openconfig.impl.util.OpenConfigUtil.APPLICATION_PEER_GROUP_NAME;
+import static org.opendaylight.protocol.bgp.openconfig.impl.util.OpenConfigUtil.toPeerType;
import com.google.common.base.Optional;
import java.math.BigDecimal;
new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder()
.setAuthPassword(password != null ? password.getValue() : null)
.setPeerAs(remoteAs)
- .setPeerType(toPeerTye(peerRole))
+ .setPeerType(toPeerType(peerRole))
.setSendCommunity(CommunityType.NONE)
.setRouteFlapDamping(Boolean.FALSE)
.build());
return neighborBuilder.build();
}
- private static PeerType toPeerTye(final PeerRole peerRole) {
- switch (peerRole) {
- case Ibgp:
- case RrClient:
- return PeerType.INTERNAL;
- case Ebgp:
- return PeerType.EXTERNAL;
- case Internal:
- break;
- default:
- break;
- }
- return null;
- }
-
@Override
public Neighbor fromApplicationPeer(final ApplicationRibId applicationRibId, final BgpId bgpId) {
final NeighborBuilder neighborBuilder = new NeighborBuilder();
}
public static AfiSafi toGlobalAfiSafiAddPath(final AfiSafi afiSafi, final BgpTableType tableType,
- final Map<TablesKey, PathSelectionMode> multiPathTables) {
+ final Map<TablesKey, PathSelectionMode> multiPathTables) {
final PathSelectionMode pathSelection = multiPathTables.get(new TablesKey(tableType.getAfi(), tableType.getSafi()));
if (pathSelection == null) {
return afiSafi;
maxPaths = 0L;
}
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2 addPath = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2Builder()
- .setReceive(false)
- .setSendMax(Shorts.checkedCast(maxPaths))
- .build();
+ .setReceive(true)
+ .setSendMax(Shorts.checkedCast(maxPaths))
+ .build();
return new AfiSafiBuilder(afiSafi)
- .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2.class,
+ .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2.class,
addPath).build();
}
public static AfiSafi toNeighborAfiSafiAddPath(final AfiSafi afiSafi, final BgpTableType tableType, final List<AddressFamilies> capabilities) {
- final Optional<AddressFamilies> capability = Iterables.tryFind(capabilities, af -> af.getAfi().equals(tableType.getAfi()) && af.getSafi().equals(tableType.getSafi()));
+ final Optional<AddressFamilies> capability = Iterables.tryFind(capabilities,
+ af -> af.getAfi().equals(tableType.getAfi()) && af.getSafi().equals(tableType.getSafi()));
if (!capability.isPresent()) {
return afiSafi;
}
return new AfiSafiBuilder(afiSafi)
- .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1.class,
+ .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1.class,
fromSendReceiveMode(capability.get().getSendReceive())).build();
}
private static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1 fromSendReceiveMode(final SendReceive mode) {
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1Builder builder =
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1Builder();
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1Builder();
switch (mode) {
case Both:
builder.setReceive(true).setSendMax((short) 0);
return PeerRole.Ibgp;
}
+ public static PeerType toPeerType(final PeerRole peerRole) {
+ switch (peerRole) {
+ case Ibgp:
+ case RrClient:
+ return PeerType.INTERNAL;
+ case Ebgp:
+ return PeerType.EXTERNAL;
+ case Internal:
+ break;
+ default:
+ break;
+ }
+ return null;
+ }
+
private static boolean isRrClient(final Neighbor neighbor) {
final RouteReflector routeReflector = neighbor.getRouteReflector();
if (routeReflector != null && routeReflector.getConfig() != null) {
--- /dev/null
+/*
+ * Copyright (c) 2016 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.openconfig.impl;
+
+import static junit.framework.TestCase.assertFalse;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.opendaylight.protocol.bgp.openconfig.impl.util.OpenConfigUtil.APPLICATION_PEER_GROUP_NAME;
+
+import com.google.common.primitives.Shorts;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
+import org.opendaylight.protocol.bgp.mode.impl.add.all.paths.AllPathSelection;
+import org.opendaylight.protocol.bgp.mode.impl.add.n.paths.AddPathBestNPathSelection;
+import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafiBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.AfiSafisBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.RouteReflectorBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.TimersBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.TransportBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.peer.group.PeerGroupBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.Bgp;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.BgpBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.GlobalBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.NeighborsBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.PeerGroupsBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.CommunityType;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV6UNICAST;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.PeerType;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.ProtocolBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.ProtocolKey;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.BGP;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.FlowspecSubsequentAddressFamily;
+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.SendReceive;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.add.path.capability.AddressFamilies;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.add.path.capability.AddressFamiliesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Config1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Config1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Config2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Config2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.IPV6FLOW;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Protocol1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Protocol1Builder;
+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.PeerRole;
+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.rib.TablesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
+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;
+
+public class BGPOpenConfigMappingServiceImplTest {
+ private static final Long ALL_PATHS = 0L;
+ private static final Long N_PATHS = 2L;
+ private static final PathSelectionMode ADD_PATH_BEST_N_PATH_SELECTION = new AddPathBestNPathSelection(N_PATHS);
+ private static final PathSelectionMode ADD_PATH_BEST_ALL_PATH_SELECTION = new AllPathSelection();
+ private static final BGPOpenConfigMappingServiceImpl OPENCONFIG = new BGPOpenConfigMappingServiceImpl();
+ private static final AsNumber AS = new AsNumber(72L);
+ private static final IpAddress IPADDRESS = new IpAddress(new Ipv4Address("127.0.0.1"));
+ private static final BgpId BGP_ID = new BgpId(IPADDRESS.getIpv4Address());
+ private static final RibId RIB_ID = new RibId("bgp");
+ private static final List<AddressFamilies> FAMILIES;
+ private static final List<BgpTableType> TABLE_TYPES;
+ private static final List<AfiSafi> AFISAFIS = new ArrayList<>();
+ private static final BigDecimal DEFAULT_TIMERS = BigDecimal.valueOf(30);
+ private static final PortNumber PORT_NUMBER = new PortNumber(179);
+
+ static {
+ FAMILIES = new ArrayList<>();
+ FAMILIES.add(new AddressFamiliesBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
+ .setSendReceive(SendReceive.Both).build());
+ FAMILIES.add(new AddressFamiliesBuilder().setAfi(Ipv6AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
+ .setSendReceive(SendReceive.Send).build());
+ FAMILIES.add(new AddressFamiliesBuilder().setAfi(Ipv6AddressFamily.class).setSafi(FlowspecSubsequentAddressFamily.class)
+ .setSendReceive(SendReceive.Receive).build());
+ TABLE_TYPES = new ArrayList<>();
+ TABLE_TYPES.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
+ TABLE_TYPES.add(new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class));
+ AFISAFIS.add(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
+ .addAugmentation(AfiSafi2.class, new AfiSafi2Builder().setReceive(true).setSendMax(Shorts.checkedCast(N_PATHS)).build()).build());
+ AFISAFIS.add(new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class)
+ .addAugmentation(AfiSafi2.class, new AfiSafi2Builder().setReceive(true).setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
+ }
+
+ @Test
+ public void toTableTypes() {
+ final List<AfiSafi> families = new ArrayList<>();
+ families.add(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class).build());
+ families.add(new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class).build());
+ final List<BgpTableType> result = OPENCONFIG.toTableTypes(families);
+ assertEquals(TABLE_TYPES, result);
+ }
+
+ @Test
+ public void toPathSelectionMode() {
+ final List<AfiSafi> families = new ArrayList<>();
+ families.add(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
+ .addAugmentation(AfiSafi2.class, new AfiSafi2Builder().setSendMax(Shorts.checkedCast(N_PATHS)).build()).build());
+ families.add(new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class)
+ .addAugmentation(AfiSafi2.class, new AfiSafi2Builder().setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
+ final Map<BgpTableType, PathSelectionMode> result = OPENCONFIG.toPathSelectionMode(families);
+ final Map<BgpTableType, PathSelectionMode> expected = new HashMap<>();
+ expected.put(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class), ADD_PATH_BEST_N_PATH_SELECTION);
+ expected.put(new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class), ADD_PATH_BEST_ALL_PATH_SELECTION);
+ assertEquals(expected.get(0), result.get(0));
+ assertEquals(expected.get(1), result.get(1));
+ }
+
+ @Test
+ public void isApplicationPeer() {
+ assertFalse(OPENCONFIG.isApplicationPeer(new NeighborBuilder().setConfig(new ConfigBuilder().build()).build()));
+ final Neighbor neighbor = new NeighborBuilder().setConfig(new ConfigBuilder()
+ .addAugmentation(Config2.class, new Config2Builder().setPeerGroup(APPLICATION_PEER_GROUP_NAME).build())
+ .build()).build();
+ assertTrue(OPENCONFIG.isApplicationPeer(neighbor));
+ }
+
+ @Test
+ public void toPeerRole() {
+ Neighbor neighbor = new NeighborBuilder().setConfig(new ConfigBuilder().setPeerType(PeerType.EXTERNAL).build()).build();
+ PeerRole peerRoleResult = OPENCONFIG.toPeerRole(neighbor);
+ Assert.assertEquals(PeerRole.Ebgp, peerRoleResult);
+
+ neighbor = new NeighborBuilder().setConfig(new ConfigBuilder().setPeerType(PeerType.INTERNAL).build()).build();
+ peerRoleResult = OPENCONFIG.toPeerRole(neighbor);
+ Assert.assertEquals(PeerRole.Ibgp, peerRoleResult);
+
+ neighbor = new NeighborBuilder()
+ .setRouteReflector(new RouteReflectorBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp
+ .neighbor.group.route.reflector.ConfigBuilder().setRouteReflectorClient(true).build()).build()).build();
+ peerRoleResult = OPENCONFIG.toPeerRole(neighbor);
+ Assert.assertEquals(PeerRole.RrClient, peerRoleResult);
+ }
+
+ @Test
+ public void toAddPathCapability() {
+ final List<AfiSafi> families = new ArrayList<>();
+ families.add(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
+ .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1.class,
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1Builder()
+ .setReceive(true).setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
+ families.add(new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class)
+ .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1.class,
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1Builder()
+ .setReceive(false).setSendMax(Shorts.checkedCast(N_PATHS)).build()).build());
+ families.add(new AfiSafiBuilder().setAfiSafiName(IPV6FLOW.class)
+ .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1.class,
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1Builder()
+ .setReceive(false).build()).build());
+ final List<AddressFamilies> result = OPENCONFIG.toAddPathCapability(families);
+ assertEquals(FAMILIES, result);
+ }
+
+ @Test
+ public void toSendReceiveMode() {
+ final Map<TablesKey, PathSelectionMode> bgpTableKeyPsm = new HashMap<>();
+ bgpTableKeyPsm.put(new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class), ADD_PATH_BEST_N_PATH_SELECTION);
+ bgpTableKeyPsm.put(new TablesKey(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class), ADD_PATH_BEST_ALL_PATH_SELECTION);
+
+ final Protocol result = OPENCONFIG.fromRib(BGP_ID, new ClusterIdentifier("192.168.1.2"), RIB_ID, AS, TABLE_TYPES, bgpTableKeyPsm);
+ final Bgp globalBgp = new BgpBuilder()
+ .setGlobal(new GlobalBuilder()
+ .setAfiSafis(new AfiSafisBuilder().setAfiSafi(AFISAFIS).build())
+ .setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base
+ .ConfigBuilder()
+ .setAs(AS).setRouterId(BGP_ID).build()).build())
+ .setPeerGroups(new PeerGroupsBuilder().setPeerGroup(Collections.singletonList(new PeerGroupBuilder().setPeerGroupName("application-peers").build())).build())
+ .setNeighbors(new NeighborsBuilder().build())
+ .build();
+ final Protocol expected = new ProtocolBuilder()
+ .setKey(new ProtocolKey(BGP.class, RIB_ID.getValue())).addAugmentation(Protocol1.class, new Protocol1Builder().setBgp(globalBgp).build()).build();
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void fromBgpPeer() {
+ final Neighbor result = OPENCONFIG.fromBgpPeer(FAMILIES, TABLE_TYPES, 30, IPADDRESS, true, null, PORT_NUMBER, 30, AS, PeerRole.Ibgp, null);
+ final List<AfiSafi> afisafis = new ArrayList<>();
+ afisafis.add(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
+ .addAugmentation(AfiSafi1.class, new AfiSafi1Builder().setReceive(true).setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
+ afisafis.add(new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class)
+ .addAugmentation(AfiSafi1.class, new AfiSafi1Builder().setReceive(false).setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
+ final Neighbor expected = new NeighborBuilder()
+ .setAfiSafis(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.AfiSafisBuilder().setAfiSafi(afisafis).build())
+ .setConfig(new ConfigBuilder().setPeerAs(AS).setPeerType(PeerType.INTERNAL).setRouteFlapDamping(false).setSendCommunity(CommunityType.NONE).build())
+ .setNeighborAddress(IPADDRESS)
+ .setRouteReflector(new RouteReflectorBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp
+ .neighbor.group.route.reflector.ConfigBuilder().setRouteReflectorClient(false).build()).build())
+ .setTimers(new TimersBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group
+ .timers.ConfigBuilder().setHoldTime(DEFAULT_TIMERS).setMinimumAdvertisementInterval(DEFAULT_TIMERS)
+ .setKeepaliveInterval(DEFAULT_TIMERS).setConnectRetry(DEFAULT_TIMERS).build()).build())
+ .setTransport(new TransportBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor
+ .group.transport.ConfigBuilder().setMtuDiscovery(false).setPassiveMode(false).addAugmentation(Config1.class, new Config1Builder()
+ .setRemotePort(new PortNumber(179)).build()).build()).build())
+ .build();
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void fromApplicationPeer() {
+ final ApplicationRibId app = new ApplicationRibId("app");
+ final Neighbor result = OPENCONFIG.fromApplicationPeer(app, BGP_ID);
+ final Neighbor expected = new NeighborBuilder().setConfig(new ConfigBuilder().setDescription(app.getValue())
+ .addAugmentation(Config2.class, new Config2Builder().setPeerGroup(APPLICATION_PEER_GROUP_NAME).build()).build())
+ .setNeighborAddress(IPADDRESS).build();
+ assertEquals(expected, result);
+ }
+}
\ No newline at end of file
package org.opendaylight.protocol.bgp.openconfig.impl.util;
+import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.opendaylight.protocol.bgp.openconfig.impl.util.OpenConfigUtil.APPLICATION_PEER_GROUP_NAME;
import static org.opendaylight.protocol.bgp.openconfig.impl.util.OpenConfigUtil.toAfiSafi;
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
+import com.google.common.primitives.Shorts;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
+import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
+import org.opendaylight.protocol.bgp.mode.impl.add.all.paths.AllPathSelection;
+import org.opendaylight.protocol.bgp.mode.impl.add.n.paths.AddPathBestNPathSelection;
import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafiBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.use.multiple.paths.UseMultiplePaths;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.AfiSafi1;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.AfiSafi2;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.RouteReflectorBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborBuilder;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV6UNICAST;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.PeerType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.L2vpnAddressFamily;
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.SendReceive;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.add.path.capability.AddressFamiliesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Config2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Config2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
+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;
public class OpenConfigUtilTest {
-
+ private static final Long ALL_PATHS = 0L;
+ private static final Long N_PATHS = 2L;
+ private static final PathSelectionMode ADD_PATH_BEST_N_PATH_SELECTION = new AddPathBestNPathSelection(N_PATHS);
+ private static final PathSelectionMode ADD_PATH_BEST_ALL_PATH_SELECTION = new AllPathSelection();
private static final BgpTableType BGP_TABLE_TYPE_IPV4 = new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+ private static final BgpTableType BGP_TABLE_TYPE_IPV6 = new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class);
private static final AfiSafi AFISAFI_IPV4 = new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class).build();
+ private static final String TEST = "/modules/module[type='dom-concurrent-data-broker'][name='concurrent-data-broker']";
+ private static final TablesKey K4 = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
@Test
public void testToAfiSafi() {
- assertEquals(toAfiSafi(BGP_TABLE_TYPE_IPV4).get(), AFISAFI_IPV4);
+ assertEquals(AFISAFI_IPV4, toAfiSafi(BGP_TABLE_TYPE_IPV4).get());
+ assertEquals(Optional.absent(), toAfiSafi(new BgpTableTypeImpl(L2vpnAddressFamily.class, UnicastSubsequentAddressFamily.class)));
+ }
+
+ @Test
+ public void isAppNeighbor() {
+ assertFalse(OpenConfigUtil.isAppNeighbor(new NeighborBuilder().setConfig(new ConfigBuilder().build()).build()));
+ final Neighbor neighbor = new NeighborBuilder().setConfig(new ConfigBuilder()
+ .addAugmentation(Config2.class, new Config2Builder().setPeerGroup(APPLICATION_PEER_GROUP_NAME).build())
+ .build()).build();
+ assertTrue(OpenConfigUtil.isAppNeighbor(neighbor));
}
@Test
Assert.assertEquals(Collections.singletonList(AFISAFI_IPV4), afiSafis);
}
+ @Test
+ public void toPeerRole() {
+ Neighbor neighbor = new NeighborBuilder().setConfig(new ConfigBuilder().setPeerType(PeerType.EXTERNAL).build()).build();
+ PeerRole peerRoleResult = OpenConfigUtil.toPeerRole(neighbor);
+ Assert.assertEquals(PeerRole.Ebgp, peerRoleResult);
+
+ neighbor = new NeighborBuilder().setConfig(new ConfigBuilder().setPeerType(PeerType.INTERNAL).build()).build();
+ peerRoleResult = OpenConfigUtil.toPeerRole(neighbor);
+ Assert.assertEquals(PeerRole.Ibgp, peerRoleResult);
+
+ neighbor = new NeighborBuilder()
+ .setRouteReflector(new RouteReflectorBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp
+ .neighbor.group.route.reflector.ConfigBuilder().setRouteReflectorClient(true).build()).build()).build();
+ peerRoleResult = OpenConfigUtil.toPeerRole(neighbor);
+ Assert.assertEquals(PeerRole.RrClient, peerRoleResult);
+ }
+
+ @Test
+ public void toPeerType() {
+ Assert.assertEquals(PeerType.EXTERNAL, OpenConfigUtil.toPeerType(PeerRole.Ebgp));
+ Assert.assertEquals(PeerType.INTERNAL, OpenConfigUtil.toPeerType(PeerRole.Ibgp));
+ Assert.assertNull(OpenConfigUtil.toPeerType(PeerRole.Internal));
+ Assert.assertEquals(PeerType.INTERNAL, OpenConfigUtil.toPeerType(PeerRole.RrClient));
+ }
+
+ @Test
+ public void toNeighborAfiSafiAddPath() {
+ final AfiSafi afiSafi = OpenConfigUtil.toNeighborAfiSafiAddPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4, Collections.emptyList());
+ Assert.assertEquals(AFISAFI_IPV4, afiSafi);
+
+ final AfiSafi afisafiIpv6Both = new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class)
+ .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1.class,
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1Builder()
+ .setSendMax(Shorts.checkedCast(ALL_PATHS)).setReceive(true).build()).build();
+ final AfiSafi afiSafi6 = OpenConfigUtil.toNeighborAfiSafiAddPath(afisafiIpv6Both, BGP_TABLE_TYPE_IPV6,
+ Collections.singletonList(new AddressFamiliesBuilder(BGP_TABLE_TYPE_IPV6).setSendReceive(SendReceive.Both).build()));
+ Assert.assertEquals(afisafiIpv6Both, afiSafi6);
+
+ final AfiSafi afisafiIpv6ReceiveExpected = new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class)
+ .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1.class,
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1Builder()
+ .setReceive(true).build()).build();
+ final AfiSafi afiSafi6ReceiveResult = OpenConfigUtil.toNeighborAfiSafiAddPath(afisafiIpv6ReceiveExpected, BGP_TABLE_TYPE_IPV6,
+ Collections.singletonList(new AddressFamiliesBuilder(BGP_TABLE_TYPE_IPV6).setSendReceive(SendReceive.Receive).build()));
+ Assert.assertEquals(afisafiIpv6ReceiveExpected, afiSafi6ReceiveResult);
+
+ final AfiSafi afisafiIpv6SendExpected = new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class)
+ .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1.class,
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1Builder()
+ .setSendMax(Shorts.checkedCast(ALL_PATHS)).setReceive(false).build()).build();
+ final AfiSafi afiSafi6SendResult = OpenConfigUtil.toNeighborAfiSafiAddPath(afisafiIpv6ReceiveExpected, BGP_TABLE_TYPE_IPV6,
+ Collections.singletonList(new AddressFamiliesBuilder(BGP_TABLE_TYPE_IPV6).setSendReceive(SendReceive.Send).build()));
+ Assert.assertEquals(afisafiIpv6SendExpected, afiSafi6SendResult);
+ }
+
+ @Test
+ public void toGlobalAfiSafiAddPath() {
+ final AfiSafi afiSafi = OpenConfigUtil.toGlobalAfiSafiAddPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4, Collections.emptyMap());
+ Assert.assertEquals(AFISAFI_IPV4, afiSafi);
+
+ final AfiSafi afiSafiResult = OpenConfigUtil.toGlobalAfiSafiAddPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4, Collections.singletonMap(K4,
+ ADD_PATH_BEST_N_PATH_SELECTION));
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2 addPath =
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2Builder()
+ .setSendMax(Shorts.checkedCast(N_PATHS)).setReceive(true).build();
+ final AfiSafi afisafiIpv4Psm2 = new AfiSafiBuilder(afiSafi)
+ .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2.class,
+ addPath).build();
+ Assert.assertEquals(afisafiIpv4Psm2, afiSafiResult);
+
+ final AfiSafi afiSafiAllResult = OpenConfigUtil.toGlobalAfiSafiAddPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4,
+ Collections.singletonMap(K4, ADD_PATH_BEST_ALL_PATH_SELECTION));
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2 addPathAll =
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2Builder()
+ .setSendMax(Shorts.checkedCast(ALL_PATHS)).setReceive(true).build();
+ final AfiSafi afiAll = new AfiSafiBuilder(afiSafi)
+ .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2.class,
+ addPathAll).build();
+ Assert.assertEquals(afiAll, afiSafiAllResult);
+ }
+
@Test(expected = UnsupportedOperationException.class)
public void testPrivateConstructor() throws Throwable {
final Constructor<OpenConfigUtil> c = OpenConfigUtil.class.getDeclaredConstructor();
public final class IdentifierUtils {
private static final Predicate<PathArgument> IS_PEER = input -> input instanceof NodeIdentifierWithPredicates && Peer.QNAME.equals(input.getNodeType());
- private static final Predicate<PathArgument> IS_TABLES = input -> Tables.QNAME.equals(input.getNodeType());
+ private static final Predicate<PathArgument> IS_TABLES = input -> input instanceof NodeIdentifierWithPredicates && Tables.QNAME.equals(input.getNodeType());
private static final QName PEER_ID = QName.create(Peer.QNAME, "peer-id").intern();
private IdentifierUtils() {
this.pathIdNid = new NodeIdentifier(this.pathIdQname);
}
- public final NodeIdentifier routePathIdNid() {
+ protected final NodeIdentifier routePathIdNid() {
return this.pathIdNid;
}
*
* @author Thomas Pantelis
*/
-public class SimpleRIBExtensionProviderContextActivator implements AutoCloseable {
+public final class SimpleRIBExtensionProviderContextActivator implements AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(SimpleRIBExtensionProviderContextActivator.class);
private final RIBExtensionProviderContext providerContext;
--- /dev/null
+/*
+ * Copyright (c) 2016 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.spi;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+
+public class AddPathRibSupportTest {
+
+ private static final NodeIdentifier QNAME = new NodeIdentifier(QName.create("test").intern());
+ private static class AddPathRibSupportLocalTest implements AddPathRibSupport{}
+
+ @Test
+ public void defaultAddPathRibSupport() {
+ final AddPathRibSupportLocalTest test = new AddPathRibSupportLocalTest();
+ assertEquals((Long) NON_PATH_ID, test.extractPathId(null));
+ assertNull(test.getRouteIdAddPath(NON_PATH_ID, null));
+ assertEquals(QNAME, test.createRouteKeyPathArgument(QNAME));
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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.spi;
+
+import static org.junit.Assert.assertEquals;
+
+import com.google.common.collect.ImmutableMap;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import org.junit.Test;
+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.PeerId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.LocRib;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.Peer;
+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.UnicastSubsequentAddressFamily;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+
+public class IdentifierUtilsTest {
+ private static final QName PEER_ID_QNAME = QName.create(Peer.QNAME, "peer-id").intern();
+ private static final QName TABLES_KEY_QNAME = QName.create(Tables.QNAME, "tables-key").intern();
+ private static final TablesKey TK = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+ private static final PeerId PEER_ID = new PeerId("127.0.0.1");
+ private static final NodeIdentifierWithPredicates NIWP_PEER = new NodeIdentifierWithPredicates(Peer.QNAME, ImmutableMap.of(PEER_ID_QNAME, PEER_ID.getValue()));
+ private static final NodeIdentifierWithPredicates NIWP_TABLE = new NodeIdentifierWithPredicates(Tables.QNAME, ImmutableMap.of(TABLES_KEY_QNAME, TK));
+ private static final YangInstanceIdentifier YII_PEER;
+ private static final YangInstanceIdentifier YII_TABLE;
+
+ static {
+ YII_PEER = YangInstanceIdentifier.builder().node(BgpRib.QNAME).node(Peer.QNAME).nodeWithKey(Peer.QNAME, PEER_ID_QNAME, PEER_ID.getValue()).build();
+ YII_TABLE = YangInstanceIdentifier.builder().node(LocRib.QNAME).node(Tables.QNAME).nodeWithKey(Tables.QNAME, TABLES_KEY_QNAME, TK).build();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testPrivateConstructor() throws Throwable {
+ final Constructor<IdentifierUtils> c = IdentifierUtils.class.getDeclaredConstructor();
+ c.setAccessible(true);
+ try {
+ c.newInstance();
+ } catch (final InvocationTargetException e) {
+ throw e.getCause();
+ }
+ }
+
+ @Test
+ public void testPeerPath() throws Exception {
+ final YangInstanceIdentifier result = IdentifierUtils.peerPath(YII_PEER);
+ assertEquals(YII_PEER, result);
+ }
+
+ @Test
+ public void testPeerKey() throws Exception {
+ final NodeIdentifierWithPredicates result = IdentifierUtils.peerKey(YII_PEER);
+ assertEquals(NIWP_PEER, result);
+ }
+
+ @Test
+ public void testPeerId() throws Exception {
+ final PeerId result = IdentifierUtils.peerId(NIWP_PEER);
+ assertEquals(PEER_ID, result);
+ }
+
+ @Test
+ public void testPeerKeyToPeerId() throws Exception {
+ final PeerId result = IdentifierUtils.peerKeyToPeerId(YII_PEER);
+ assertEquals(PEER_ID, result);
+ }
+
+ @Test
+ public void testTableKey() throws Exception {
+ final NodeIdentifierWithPredicates result = IdentifierUtils.tableKey(YII_TABLE);
+ assertEquals(NIWP_TABLE, result);
+ }
+
+ @Test
+ public void testDomPeerId() throws Exception {
+ final NodeIdentifierWithPredicates result = IdentifierUtils.domPeerId(PEER_ID);
+ assertEquals(NIWP_PEER, result);
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 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.spi;
+
+import static junit.framework.TestCase.assertFalse;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doReturn;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableMap;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4Prefixes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4Route;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4Routes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4RoutesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.MultiPathAbstractTest;
+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.path.attributes.Attributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.DestinationType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
+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.bgp.rib.rib.LocRib;
+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.rib.rev130925.rib.tables.Routes;
+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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeSchemaAwareBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
+
+public class MultiPathAbstractRIBSupportTest {
+ private final static long PATH_ID = 0;
+ private final static String ROUTE_KEY = "prefix";
+ private static final String PREFIX = "1.2.3.4/32";
+ private static final QName PATH_ID_QNAME = QName.create(Ipv4Route.QNAME, "path-id").intern();
+ private static final QName PREFIX_QNAME = QName.create(Ipv4Route.QNAME, ROUTE_KEY).intern();
+ private static final NodeIdentifierWithPredicates PREFIX_NII = new NodeIdentifierWithPredicates(Ipv4Route.QNAME,
+ ImmutableMap.of(QName.create(Ipv4Route.QNAME, ROUTE_KEY).intern(), PREFIX));
+ private static final MultiPathAbstractTest MULTI_PATH_ABSTRACT_TEST = new MultiPathAbstractTest();
+ private static final TablesKey TABLES_KEY = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+ private static final YangInstanceIdentifier LOC_RIB_TARGET = YangInstanceIdentifier.create(YangInstanceIdentifier.of(BgpRib.QNAME)
+ .node(LocRib.QNAME).node(Tables.QNAME).node(RibSupportUtils.toYangTablesKey(TABLES_KEY)).getPathArguments());
+ private static final NodeIdentifier ROUTES_IDENTIFIER = new NodeIdentifier(Routes.QNAME);
+ private static final NodeIdentifier IPV4_ROUTES_IDENTIFIER = new NodeIdentifier(Ipv4Routes.QNAME);
+ private DataTreeCandidateNode emptyTree;
+ private DataTreeCandidateNode emptySubTree;
+ private DataTreeCandidateNode subTree;
+ private DOMDataWriteTransaction tx;
+ private ContainerNode nlri;
+ private Map<YangInstanceIdentifier, NormalizedNode<?, ?>> routes;
+ private ContainerNode attributes;
+ private MapEntryNode mapEntryNode;
+
+ @Before
+ public void setUp() {
+ this.routes = new HashMap<>();
+ MockitoAnnotations.initMocks(this);
+ this.emptyTree = Mockito.mock(DataTreeCandidateNode.class);
+ this.emptySubTree = Mockito.mock(DataTreeCandidateNode.class);
+ this.subTree = Mockito.mock(DataTreeCandidateNode.class);
+ final DataTreeCandidateNode emptyNode = Mockito.mock(DataTreeCandidateNode.class);
+ final DataTreeCandidateNode node = Mockito.mock(DataTreeCandidateNode.class);
+ doReturn(null).when(this.emptyTree).getModifiedChild(IPV4_ROUTES_IDENTIFIER);
+
+ doReturn(emptyNode).when(this.emptySubTree).getModifiedChild(IPV4_ROUTES_IDENTIFIER);
+ doReturn(null).when(emptyNode).getModifiedChild(new NodeIdentifier(Ipv4Route.QNAME));
+
+ doReturn(node).when(this.subTree).getModifiedChild(IPV4_ROUTES_IDENTIFIER);
+ doReturn(node).when(node).getModifiedChild(new NodeIdentifier(Ipv4Route.QNAME));
+ final Collection<DataTreeCandidateNode> emptyCollection = new HashSet<>();
+ doReturn(emptyCollection).when(node).getChildNodes();
+
+ this.tx = Mockito.mock(DOMDataWriteTransaction.class);
+ this.nlri = Mockito.mock(ContainerNode.class);
+ this.attributes = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(QName.create(Ipv4Routes.QNAME, Attributes.QNAME
+ .getLocalName().intern()))).build();
+ final ContainerNode destination = Mockito.mock(ContainerNode.class);
+ final ContainerNode route = Mockito.mock(ContainerNode.class);
+ final Optional optional = Mockito.mock(Optional.class);
+ final Optional destinationOptional = Mockito.mock(Optional.class);
+ final Optional destinationsOptional = Mockito.mock(Optional.class);
+ final ChoiceNode destinations = Mockito.mock(ChoiceNode.class);
+
+ doReturn(optional).when(this.nlri).getChild(new NodeIdentifier(WithdrawnRoutes.QNAME));
+ doReturn(optional).when(this.nlri).getChild(new NodeIdentifier(AdvertizedRoutes.QNAME));
+ doReturn(true).when(optional).isPresent();
+ doReturn(destination).when(optional).get();
+ doReturn(destinationOptional).when(destination).getChild(new NodeIdentifier(DestinationType.QNAME));
+ doReturn(true).when(destinationOptional).isPresent();
+ doReturn(destinations).when(destinationOptional).get();
+ doReturn(destinationsOptional).when(destinations).getChild(new NodeIdentifier(Ipv4Prefixes.QNAME));
+ doReturn(true).when(destinationsOptional).isPresent();
+ doReturn(route).when(destinationsOptional).get();
+ doReturn(emptyCollection).when(route).getValue();
+
+ doAnswer(invocation -> {
+ final Object[] args = invocation.getArguments();
+ MultiPathAbstractRIBSupportTest.this.routes.remove(args[1]);
+ return args[1];
+ }).when(this.tx).delete(Mockito.eq(LogicalDatastoreType.OPERATIONAL), Mockito.any(YangInstanceIdentifier.class));
+ doAnswer(invocation -> {
+ final Object[] args = invocation.getArguments();
+ final NormalizedNode<?, ?> node1 = (NormalizedNode<?, ?>) args[2];
+ MultiPathAbstractRIBSupportTest.this.routes.put((YangInstanceIdentifier) args[1], node1);
+ return args[1];
+ }).when(this.tx).put(Mockito.eq(LogicalDatastoreType.OPERATIONAL), Mockito.any(YangInstanceIdentifier.class), Mockito.any(NormalizedNode.class));
+
+ this.mapEntryNode = Mockito.mock(MapEntryNode.class);
+ }
+
+ @Test
+ public void pathIdQName() {
+ final MultiPathAbstractTest multiPath = MULTI_PATH_ABSTRACT_TEST;
+ assertEquals(PATH_ID_QNAME, multiPath.pathIdQName());
+ }
+
+ @Test
+ public void extractPathId() {
+ final NodeIdentifier nii = new NodeIdentifier(PATH_ID_QNAME);
+ final ContainerNode cont = ImmutableContainerNodeSchemaAwareBuilder.create().withNodeIdentifier(nii).
+ addChild(new ImmutableLeafNodeBuilder<>().withNodeIdentifier(nii).withValue(PATH_ID).build()).build();
+ assertEquals((Long) PATH_ID, MULTI_PATH_ABSTRACT_TEST.extractPathId(cont));
+ }
+
+ @Test
+ public void getRouteIdAddPath() {
+ final NodeIdentifierWithPredicates routeIdPa =
+ new NodeIdentifierWithPredicates(Ipv4Route.QNAME, ImmutableMap.of(PATH_ID_QNAME, PATH_ID, PREFIX_QNAME, PREFIX));
+ assertEquals(routeIdPa, MULTI_PATH_ABSTRACT_TEST.getRouteIdAddPath(PATH_ID, PREFIX_NII));
+
+ }
+
+ @Test
+ public void createRouteKeyPathArgument() {
+ assertEquals(PREFIX_NII, MULTI_PATH_ABSTRACT_TEST.createRouteKeyPathArgument(PREFIX_NII));
+ }
+
+ @Test
+ public void routesCaseClass() throws Exception {
+ assertEquals(Ipv4RoutesCase.class, MULTI_PATH_ABSTRACT_TEST.routesCaseClass());
+ }
+
+ @Test
+ public void routesContainerClass() throws Exception {
+ assertEquals(Ipv4Routes.class, MULTI_PATH_ABSTRACT_TEST.routesContainerClass());
+ }
+
+ @Test
+ public void routesListClass() throws Exception {
+ assertEquals(Ipv4Route.class, MULTI_PATH_ABSTRACT_TEST.routesListClass());
+ }
+
+ @Test
+ public void routeQName() throws Exception {
+ assertEquals(Ipv4Route.QNAME, MULTI_PATH_ABSTRACT_TEST.routeQName());
+ }
+
+ @Test
+ public void emptyRoutes() throws Exception {
+ final ChoiceNode emptyRoutes = Builders.choiceBuilder().withNodeIdentifier(ROUTES_IDENTIFIER).addChild(Builders.containerBuilder()
+ .withNodeIdentifier(IPV4_ROUTES_IDENTIFIER).withChild(ImmutableNodes.mapNodeBuilder(MULTI_PATH_ABSTRACT_TEST.routeQName()
+ ).build()).build())
+ .build();
+ assertEquals(emptyRoutes, MULTI_PATH_ABSTRACT_TEST.emptyRoutes());
+ }
+
+ @Test
+ public void routeNid() throws Exception {
+ assertEquals(new NodeIdentifier(Ipv4Route.QNAME), MULTI_PATH_ABSTRACT_TEST.routeNid());
+ }
+
+ @Test
+ public void getAfi() throws Exception {
+ assertEquals(Ipv4AddressFamily.class, MULTI_PATH_ABSTRACT_TEST.getAfi());
+ }
+
+ @Test
+ public void getSafi() throws Exception {
+ assertEquals(UnicastSubsequentAddressFamily.class, MULTI_PATH_ABSTRACT_TEST.getSafi());
+ }
+
+ @Test
+ public void routesContainerIdentifier() throws Exception {
+ assertEquals(IPV4_ROUTES_IDENTIFIER, MULTI_PATH_ABSTRACT_TEST.routesContainerIdentifier());
+
+ }
+
+ @Test
+ public void routeAttributesIdentifier() throws Exception {
+ assertEquals(new NodeIdentifier(QName.create(Ipv4Routes.QNAME, Attributes.QNAME.getLocalName().intern())), MULTI_PATH_ABSTRACT_TEST.routeAttributesIdentifier());
+ }
+
+ @Test
+ public void routePath() throws Exception {
+ Assert.assertEquals(LOC_RIB_TARGET.node(ROUTES_IDENTIFIER).node(Ipv4Routes.QNAME).node(Ipv4Route.QNAME).node(PREFIX_NII),
+ MULTI_PATH_ABSTRACT_TEST.routePath(LOC_RIB_TARGET.node(Routes.QNAME), PREFIX_NII));
+ }
+
+ @Test
+ public void changedRoutes() throws Exception {
+ Assert.assertTrue(MULTI_PATH_ABSTRACT_TEST.changedRoutes(this.emptyTree).isEmpty());
+ Assert.assertTrue(MULTI_PATH_ABSTRACT_TEST.changedRoutes(this.emptySubTree).isEmpty());
+ Assert.assertNotNull(MULTI_PATH_ABSTRACT_TEST.changedRoutes(this.subTree));
+ }
+
+ @Test
+ public void putRoutes() throws Exception {
+ MULTI_PATH_ABSTRACT_TEST.putRoutes(this.tx, LOC_RIB_TARGET, this.nlri, this.attributes);
+ assertFalse(this.routes.isEmpty());
+ }
+
+ @Test
+ public void deleteRoutes() throws Exception {
+ MULTI_PATH_ABSTRACT_TEST.deleteRoutes(this.tx, LOC_RIB_TARGET, this.nlri);
+ assertTrue(this.routes.isEmpty());
+ }
+
+
+ @Test
+ public void buildUpdate() throws Exception {
+ final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(
+ new Ipv4Address("10.0.0.2")).build()).build();
+ final Attributes attr = new AttributesBuilder().setCNextHop(nextHop).build();
+ final Collection<MapEntryNode> routes = new HashSet<>();
+
+ assertEquals(new UpdateBuilder().setAttributes(new AttributesBuilder().build()).build(),
+ MULTI_PATH_ABSTRACT_TEST.buildUpdate(routes, routes, attr));
+
+ routes.add(this.mapEntryNode);
+ final MpReachNlri mpReach = new MpReachNlriBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
+ .setCNextHop(nextHop).setAdvertizedRoutes(new AdvertizedRoutesBuilder().build()).build();
+
+ final Attributes attMpR = new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mpReach).build())
+ .build();
+ assertEquals(new UpdateBuilder().setAttributes(attMpR).build(), MULTI_PATH_ABSTRACT_TEST.buildUpdate(routes, Collections.emptySet(), attr));
+
+ final MpUnreachNlri mpUnreach = new MpUnreachNlriBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
+ .setWithdrawnRoutes(new WithdrawnRoutesBuilder().build()).build();
+
+ final Attributes attMpU = new AttributesBuilder().addAugmentation(Attributes2.class, new Attributes2Builder().setMpUnreachNlri(mpUnreach)
+ .build()).build();
+ assertEquals(new UpdateBuilder().setAttributes(attMpU).build(), MULTI_PATH_ABSTRACT_TEST.buildUpdate(Collections.emptySet(), routes, attr));
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 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.spi;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+
+public class PeerExportGroupTest {
+ @Test
+ public void defaultPeerExportGroupTest() {
+ final PeerExportGroup.PeerExporTuple peerExportGroup = new PeerExportGroup.PeerExporTuple(YangInstanceIdentifier.EMPTY, PeerRole.Ebgp);
+ assertEquals(PeerRole.Ebgp, peerExportGroup.getRole());
+ assertEquals(YangInstanceIdentifier.EMPTY, peerExportGroup.getYii());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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.spi;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import com.google.common.base.Optional;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
+
+public class PeerRoleUtilTest {
+ @Test(expected = UnsupportedOperationException.class)
+ public void testPrivateConstructor() throws Throwable {
+ final Constructor<PeerRoleUtil> c = PeerRoleUtil.class.getDeclaredConstructor();
+ c.setAccessible(true);
+ try {
+ c.newInstance();
+ } catch (final InvocationTargetException e) {
+ throw e.getCause();
+ }
+ }
+
+ @Test
+ public void roleForChange() {
+ assertNull(PeerRoleUtil.roleForChange(Optional.fromNullable(null)));
+ assertEquals(PeerRole.Ebgp, PeerRoleUtil.roleForChange(Optional.of(new ImmutableLeafNodeBuilder<>()
+ .withNodeIdentifier(PeerRoleUtil.PEER_ROLE_NID).withValue("ebgp").build())));
+ }
+
+ @Test
+ public void roleForString() {
+ assertEquals("ebgp",PeerRoleUtil.roleForString(PeerRole.Ebgp));
+ assertEquals("ibgp",PeerRoleUtil.roleForString(PeerRole.Ibgp));
+ assertEquals("rr-client",PeerRoleUtil.roleForString(PeerRole.RrClient));
+ assertEquals("internal",PeerRoleUtil.roleForString(PeerRole.Internal));
+ }
+}
\ No newline at end of file
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+
+import com.google.common.collect.ImmutableMap;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4Route;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.peer.SupportedTables;
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.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
public class RibSupportUtilsTest {
+ private final static NodeIdentifierWithPredicates NII;
+ private final static NodeIdentifierWithPredicates NII_PATH;
+ final Class<? extends AddressFamily> AFI = Ipv4AddressFamily.class;
+ final Class<? extends SubsequentAddressFamily> SAFI = UnicastSubsequentAddressFamily.class;
+ private static final TablesKey TABLE_KEY = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+ static {
+ final QName afi = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-rib?revision=2013-09-25", "afi");
+ final QName safi = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-rib?revision=2013-09-25", "safi");
+ NII = new NodeIdentifierWithPredicates(SupportedTables.QNAME, ImmutableMap.of(afi, Ipv4AddressFamily.QNAME, safi, UnicastSubsequentAddressFamily.QNAME));
+ NII_PATH = new NodeIdentifierWithPredicates(SupportedTables.QNAME,
+ ImmutableMap.of(
+ QName.create("urn:opendaylight:params:xml:ns:yang:bgp-multiprotocol?revision=2013-09-19", "afi"),
+ Ipv4AddressFamily.QNAME,
+ QName.create("urn:opendaylight:params:xml:ns:yang:bgp-multiprotocol?revision=2013-09-19", "safi"),
+ UnicastSubsequentAddressFamily.QNAME)
+ );
+ }
@Test(expected=UnsupportedOperationException.class)
public void testPrivateConstructor() throws Throwable {
@Test
public void testYangTablesKey() {
- final Class<? extends AddressFamily> afi = Ipv4AddressFamily.class;
- final Class<? extends SubsequentAddressFamily> safi = UnicastSubsequentAddressFamily.class;
- final TablesKey k = new TablesKey(afi, safi);
- final NodeIdentifierWithPredicates p = RibSupportUtils.toYangTablesKey(k);
+ final NodeIdentifierWithPredicates p = RibSupportUtils.toYangTablesKey(TABLE_KEY);
final Map<QName, Object> m = p.getKeyValues();
assertFalse(m.isEmpty());
assertEquals(Tables.QNAME, p.getNodeType());
- assertTrue(m.containsValue(BindingReflections.findQName(afi)));
- assertTrue(m.containsValue(BindingReflections.findQName(safi)));
+ assertTrue(m.containsValue(BindingReflections.findQName(AFI)));
+ assertTrue(m.containsValue(BindingReflections.findQName(SAFI)));
}
@Test
public void testYangKey() {
- final Class<? extends AddressFamily> afi = Ipv4AddressFamily.class;
- final Class<? extends SubsequentAddressFamily> safi = UnicastSubsequentAddressFamily.class;
- final TablesKey k = new TablesKey(afi, safi);
- final NodeIdentifierWithPredicates p = RibSupportUtils.toYangKey(SupportedTables.QNAME, k);
+ final NodeIdentifierWithPredicates p = RibSupportUtils.toYangKey(SupportedTables.QNAME, TABLE_KEY);
final Map<QName, Object> m = p.getKeyValues();
assertFalse(m.isEmpty());
assertEquals(SupportedTables.QNAME, p.getNodeType());
- assertTrue(m.containsValue(BindingReflections.findQName(afi)));
- assertTrue(m.containsValue(BindingReflections.findQName(safi)));
+ assertTrue(m.containsValue(BindingReflections.findQName(AFI)));
+ assertTrue(m.containsValue(BindingReflections.findQName(SAFI)));
+ }
+
+ @Test
+ public void toYangPathKey() {
+ final NodeIdentifierWithPredicates result = RibSupportUtils.toYangPathKey(SupportedTables.QNAME, AFI, SAFI);
+ assertEquals(NII_PATH.toString(), result.toString());
+
+ }
+ @Test
+ public void toYangKey() {
+ final NodeIdentifierWithPredicates result = RibSupportUtils.toYangKey(SupportedTables.QNAME, TABLE_KEY);
+ assertEquals(NII.toString(), result.toString());
}
}
--- /dev/null
+/*
+ * Copyright (c) 2016 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.spi;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collections;
+import java.util.List;
+import org.junit.Test;
+
+public class SimpleRIBExtensionProviderContextActivatorTest {
+ private static boolean RIBACTIVATED;
+
+ private static class RibActivator extends AbstractRIBExtensionProviderActivator {
+ @Override
+ protected List<AutoCloseable> startRIBExtensionProviderImpl(final RIBExtensionProviderContext context) {
+ RIBACTIVATED = true;
+ return Collections.singletonList(() -> RIBACTIVATED = false);
+ }
+ }
+
+ @Test
+ public void test() throws Exception {
+ final List<RIBExtensionProviderActivator> extensionActivators = Collections.singletonList(new RibActivator());
+ final SimpleRIBExtensionProviderContextActivator activator =
+ new SimpleRIBExtensionProviderContextActivator(new SimpleRIBExtensionProviderContext(), extensionActivators);
+ activator.start();
+ assertTrue(RIBACTIVATED);
+ activator.close();
+ assertFalse(RIBACTIVATED);
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes;
+
+import org.opendaylight.yangtools.yang.common.QName;
+
+public interface Ipv4Prefixes {
+ public static final QName QNAME = org.opendaylight.yangtools.yang.common.QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet",
+ "2015-03-05", "ipv4-prefixes").intern();
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Route;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public interface Ipv4Route extends Route {
+ public static final QName QNAME = org.opendaylight.yangtools.yang.common.QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet",
+ "2015-03-05", "ipv4-route").intern();
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes;
+
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public interface Ipv4Routes extends DataObject {
+ public static final QName QNAME = org.opendaylight.yangtools.yang.common.QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet",
+ "2015-03-05", "ipv4-routes").intern();
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes;
+
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Routes;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public interface Ipv4RoutesCase extends Routes {
+ public static final QName QNAME = org.opendaylight.yangtools.yang.common.QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet",
+ "2015-03-05", "ipv4-routes-case").intern();
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes;
+
+import com.google.common.collect.ImmutableCollection;
+import com.google.common.collect.ImmutableMap;
+import java.util.Collection;
+import javax.annotation.Nonnull;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
+import org.opendaylight.protocol.bgp.rib.spi.MultiPathAbstractRIBSupport;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.DestinationType;
+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.DataObject;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+
+public final class MultiPathAbstractTest extends MultiPathAbstractRIBSupport {
+ private final static String ROUTE_KEY = "prefix";
+ private static final String PREFIX = "1.2.3.4/32";
+
+ private static final NodeIdentifierWithPredicates PREFIX_NII = new NodeIdentifierWithPredicates(Ipv4Route.QNAME,
+ ImmutableMap.of(QName.create(Ipv4Route.QNAME, ROUTE_KEY).intern(), PREFIX));
+
+ public MultiPathAbstractTest() {
+ super(Ipv4RoutesCase.class, Ipv4Routes.class, Ipv4Route.class, Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, ROUTE_KEY, Ipv4Prefixes.QNAME);
+ }
+
+ @Nonnull
+ @Override
+ protected DestinationType buildDestination(@Nonnull final Collection<MapEntryNode> routes) {
+ return null;
+ }
+
+ @Nonnull
+ @Override
+ protected DestinationType buildWithdrawnDestination(@Nonnull final Collection<MapEntryNode> routes) {
+ return null;
+ }
+
+ @Override
+ protected void processDestination(final DOMDataWriteTransaction tx, final YangInstanceIdentifier routesPath, final ContainerNode destination,
+ final ContainerNode attributes, final ApplyRoute applyFunction) {
+ applyFunction.apply(tx, routesPath.node(Ipv4Route.QNAME), PREFIX_NII, destination, attributes);
+ }
+
+ @Nonnull
+ @Override
+ public ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects() {
+ return null;
+ }
+
+ @Nonnull
+ @Override
+ public ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects() {
+ return null;
+ }
+
+ @Override
+ public boolean isComplexRoute() {
+ return false;
+ }
+}
\ No newline at end of file
<sourceDirectory>${project.basedir}</sourceDirectory>
<includes>**\/*.java,**\/*.xml,**\/*.ini,**\/*.sh,**\/*.bat,**\/*.yang</includes>
<excludes>**\/target\/,**\/bin\/,**\/target-ide\/,**\/src/main/yang-gen-config\/,**\/src/main/yang-gen-sal\/,**\/
- .m2repo\/,**\/org/opendaylight/protocol/util/LoggerUtil.java</excludes>
+ .m2repo\/,**\/org/opendaylight/protocol/util/LoggerUtil.java,**\/org/opendaylight/protocol/util/LoggerUtilTest.java</excludes>
</configuration>
<dependencies>
<dependency>
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
+import com.google.common.net.HostAndPort;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
public class InetSocketAddressUtilTest {
- private static String ADDRESS1 = "1.1.1.1";
- private static String ADDRESS2 = "2.2.2.2";
- private static int PORT1 = 123;
- private static int PORT2 = 321;
- private static String ADDRESSES_WO_PORT = ADDRESS1 + "," + ADDRESS2;
- private static String ADDRESSES = ADDRESS1 + ":" + PORT1 + "," + ADDRESS2 + ":" + PORT2;
- private static int DEFAULT_PORT = 179;
+ private static final String ADDRESS1 = "1.1.1.1";
+ private static final String ADDRESS2 = "2.2.2.2";
+ private static final int PORT1 = 123;
+ private static final int PORT2 = 321;
+ private static final String ADDRESSES_WO_PORT = ADDRESS1 + "," + ADDRESS2;
+ private static final String ADDRESSES = ADDRESS1 + ":" + PORT1 + "," + ADDRESS2 + ":" + PORT2;
+ private static final int DEFAULT_PORT = 179;
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testPrivateConstructor() throws Throwable {
+ final Constructor<InetSocketAddressUtil> c = InetSocketAddressUtil.class.getDeclaredConstructor();
+ c.setAccessible(true);
+ try {
+ c.newInstance();
+ } catch (final InvocationTargetException e) {
+ throw e.getCause();
+ }
+ }
@Test
public void parseAddresses() throws Exception {
Assert.assertEquals(Arrays.asList(new InetSocketAddress(ADDRESS1, PORT1), new InetSocketAddress(ADDRESS2, PORT2)), actualResult);
}
+ @Test
+ public void toHostAndPort() throws Exception {
+ final HostAndPort actualResult = InetSocketAddressUtil.toHostAndPort(new InetSocketAddress(ADDRESS2, PORT2));
+ final HostAndPort expected = HostAndPort.fromString("2.2.2.2:321");
+ Assert.assertEquals(expected, actualResult);
+ }
+
@Test
public void parseAddressesDefaultPort() throws Exception {
final List<InetSocketAddress> actualResult = InetSocketAddressUtil.parseAddresses(ADDRESSES_WO_PORT, DEFAULT_PORT);
--- /dev/null
+/*
+ * Copyright (c) 2016 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.util;
+
+import static org.junit.Assert.assertEquals;
+
+import ch.qos.logback.classic.Level;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LoggerUtilTest {
+
+ @Test(expected=UnsupportedOperationException.class)
+ public void testPrivateConstructor() throws Throwable {
+ final Constructor<LoggerUtil> c = LoggerUtil.class.getDeclaredConstructor();
+ c.setAccessible(true);
+ try {
+ c.newInstance();
+ } catch (final InvocationTargetException e) {
+ throw e.getCause();
+ }
+ }
+
+ @Test
+ public void initiateLogger() {
+ LoggerUtil.initiateLogger(() -> Level.DEBUG);
+ final ch.qos.logback.classic.Logger protocolLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("org.opendaylight.protocol");
+ assertEquals(protocolLogger.getLevel(), Level.DEBUG);
+
+ final ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+ assertEquals(logger.getLevel(), Level.OFF);
+ }
+}
\ No newline at end of file