import java.util.Map;
import java.util.Map.Entry;
import java.util.function.BiConsumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
public abstract class AbstractRouteEntryTest {
protected static final long REMOTE_PATH_ID = 1;
protected static final PeerId PEER_ID = new PeerId("bgp://42.42.42.42");
- protected static final YangInstanceIdentifier PEER_YII2 = YangInstanceIdentifier.of(QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet:test", "2015-03-05", "peer2"));
+ protected static final YangInstanceIdentifier PEER_YII2 = YangInstanceIdentifier
+ .of(QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet:test",
+ "2015-03-05", "peer2"));
protected static final long AS = 64444;
protected static final UnsignedInteger ROUTER_ID = UnsignedInteger.ONE;
- protected static final TablesKey TABLES_KEY = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
- protected static final YangInstanceIdentifier LOC_RIB_TARGET = YangInstanceIdentifier.create(YangInstanceIdentifier.of(BgpRib.QNAME)
- .node(LocRib.QNAME).node(Tables.QNAME).node(RibSupportUtils.toYangTablesKey(TABLES_KEY)).getPathArguments());
+ protected static final TablesKey TABLES_KEY = new TablesKey(Ipv4AddressFamily.class,
+ UnicastSubsequentAddressFamily.class);
+ protected 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 long PATH_ID = 1;
private static final PeerId PEER_ID2 = new PeerId("bgp://43.43.43.43");
private static final String PREFIX = "1.2.3.4/32";
private static final String PREFIX2 = "2.2.2.2/32";
- private static final YangInstanceIdentifier PEER_YII = YangInstanceIdentifier.of(QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet:test", "2015-03-05", "peer1"));
+ private static final YangInstanceIdentifier PEER_YII
+ = YangInstanceIdentifier.of(QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet:test",
+ "2015-03-05", "peer1"));
private static final NodeIdentifier ROUTES_IDENTIFIER = new NodeIdentifier(Routes.QNAME);
- private static final NodeIdentifier ORIGIN_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q, Origin.QNAME.getLocalName()).intern());
- private static final NodeIdentifier ORIGIN_VALUE_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q, "value").intern());
- private static final NodeIdentifier AS_PATH_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q, AsPath.QNAME.getLocalName()).intern());
- private static final NodeIdentifier ATOMIC_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q, AtomicAggregate.QNAME.getLocalName()));
+ private static final NodeIdentifier ORIGIN_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q,
+ Origin.QNAME.getLocalName()).intern());
+ private static final NodeIdentifier ORIGIN_VALUE_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q,
+ "value").intern());
+ private static final NodeIdentifier AS_PATH_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q,
+ AsPath.QNAME.getLocalName()).intern());
+ private static final NodeIdentifier ATOMIC_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q,
+ AtomicAggregate.QNAME.getLocalName()));
private static final QName Q_NAME = BindingReflections.findQName(Ipv4Routes.class).intern();
- private static final NodeIdentifier ROUTE_ATTRIBUTES_IDENTIFIER = new NodeIdentifier(QName.create(Q_NAME, Attributes.QNAME.getLocalName().intern()));
- private static final QName PREFIX_QNAME = QName.create(Ipv4Route.QNAME, "prefix").intern();
- protected static final NodeIdentifierWithPredicates ROUTE_ID_PA = new NodeIdentifierWithPredicates(Ipv4Route.QNAME, ImmutableMap.of(PREFIX_QNAME, PREFIX));
+ private static final NodeIdentifier ROUTE_ATTRIBUTES_IDENTIFIER
+ = new NodeIdentifier(QName.create(Q_NAME, Attributes.QNAME.getLocalName().intern()));
+ private static final QName PREFIX_QNAME
+ = QName.create(Ipv4Route.QNAME, "prefix").intern();
+ protected static final NodeIdentifierWithPredicates ROUTE_ID_PA
+ = new NodeIdentifierWithPredicates(Ipv4Route.QNAME, ImmutableMap.of(PREFIX_QNAME, PREFIX));
private static final QName PATHID_QNAME = QName.create(Ipv4Route.QNAME, "path-id").intern();
- protected static final NodeIdentifierWithPredicates ROUTE_ID_PA_ADD_PATH = new NodeIdentifierWithPredicates(Ipv4Route.QNAME, ImmutableMap.of(PATHID_QNAME, PATH_ID, PREFIX_QNAME, PREFIX2));
+ protected static final NodeIdentifierWithPredicates ROUTE_ID_PA_ADD_PATH
+ = new NodeIdentifierWithPredicates(Ipv4Route.QNAME,
+ ImmutableMap.of(PATHID_QNAME, PATH_ID, PREFIX_QNAME, PREFIX2));
@Mock
protected RIBSupport ribSupport;
@Mock
protected ExportPolicyPeerTracker peerPT;
@Mock
protected PeerExportGroup peg;
- protected List<YangInstanceIdentifier> yIIChanges;
+ protected List<YangInstanceIdentifier> yiichanges;
protected NormalizedNode<?, ?> attributes;
protected YangInstanceIdentifier routePaYii;
protected YangInstanceIdentifier routePaAddPathYii;
protected void setUp() {
MockitoAnnotations.initMocks(this);
- this.yIIChanges = new ArrayList<>();
+ this.yiichanges = new ArrayList<>();
this.attributes = createAttr();
this.locRibTargetYii = LOC_RIB_TARGET.node(ROUTES_IDENTIFIER);
- this.locRibOutTargetYii = PEER_YII.node(AdjRibOut.QNAME).node(Tables.QNAME).node(RibSupportUtils.toYangTablesKey(TABLES_KEY)).node(ROUTES_IDENTIFIER);
+ this.locRibOutTargetYii = PEER_YII.node(AdjRibOut.QNAME).node(Tables.QNAME)
+ .node(RibSupportUtils.toYangTablesKey(TABLES_KEY)).node(ROUTES_IDENTIFIER);
this.routePaYii = this.locRibTargetYii.node(ROUTE_ID_PA);
this.routePaAddPathYii = this.locRibTargetYii.node(ROUTE_ID_PA_ADD_PATH);
this.routeRiboutYii = this.locRibOutTargetYii.node(ROUTE_ID_PA);
this.routeAddRiboutYii = this.locRibOutTargetYii.node(ROUTE_ID_PA_ADD_PATH);
this.routeRiboutAttYii = this.locRibOutTargetYii.node(ROUTE_ID_PA).node(ATTRS_EXTENSION_Q);
this.routeAddRiboutAttYii = this.locRibOutTargetYii.node(ROUTE_ID_PA_ADD_PATH).node(ATTRS_EXTENSION_Q);
- this.locRibOutTargetYiiPeer2 = PEER_YII2.node(AdjRibOut.QNAME).node(Tables.QNAME).node(RibSupportUtils.toYangTablesKey(TABLES_KEY)).node(ROUTES_IDENTIFIER);
+ this.locRibOutTargetYiiPeer2 = PEER_YII2.node(AdjRibOut.QNAME).node(Tables.QNAME)
+ .node(RibSupportUtils.toYangTablesKey(TABLES_KEY)).node(ROUTES_IDENTIFIER);
this.routeRiboutYiiPeer2 = this.locRibOutTargetYiiPeer2.node(ROUTE_ID_PA);
this.routeRiboutAttYiiPeer2 = this.locRibOutTargetYiiPeer2.node(ROUTE_ID_PA).node(ATTRS_EXTENSION_Q);
this.routeAddRiboutYiiPeer2 = this.locRibOutTargetYiiPeer2.node(ROUTE_ID_PA_ADD_PATH);
private void mockTransactionChain() {
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
- this.yIIChanges.add((YangInstanceIdentifier) args[1]);
+ this.yiichanges.add((YangInstanceIdentifier) args[1]);
return args[1];
- }).when(this.tx).put(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
+ }).when(this.tx)
+ .put(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
if (this.routePaYii.equals(args[1])) {
- this.yIIChanges.remove(this.routePaYii);
+ this.yiichanges.remove(this.routePaYii);
} else if (this.routePaAddPathYii.equals(args[1])) {
- this.yIIChanges.remove(this.routePaAddPathYii);
+ this.yiichanges.remove(this.routePaAddPathYii);
} else if (this.routeRiboutYii.equals(args[1])) {
- this.yIIChanges.remove(this.routeRiboutYii);
- this.yIIChanges.remove(this.routeAddRiboutAttYii);
+ this.yiichanges.remove(this.routeRiboutYii);
+ this.yiichanges.remove(this.routeAddRiboutAttYii);
} else if (this.routeAddRiboutYii.equals(args[1])) {
- this.yIIChanges.remove(this.routeAddRiboutYii);
- this.yIIChanges.remove(this.routeAddRiboutAttYii);
+ this.yiichanges.remove(this.routeAddRiboutYii);
+ this.yiichanges.remove(this.routeAddRiboutAttYii);
}
return args[1];
}).when(this.tx).delete(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class));
private void mockRibSupport() {
doReturn(ROUTE_ATTRIBUTES_IDENTIFIER).when(this.ribSupport).routeAttributesIdentifier();
- doReturn(ROUTE_ID_PA_ADD_PATH).when(this.ribSupport).getRouteIdAddPath(any(Long.class), eq(ROUTE_ID_PA_ADD_PATH));
+ doReturn(ROUTE_ID_PA_ADD_PATH).when(this.ribSupport)
+ .getRouteIdAddPath(any(Long.class), eq(ROUTE_ID_PA_ADD_PATH));
doReturn(null).when(this.ribSupport).getRouteIdAddPath(any(Long.class), eq(ROUTE_ID_PA));
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
}
private static NormalizedNode<?, ?> createAttr() {
- final ContainerNode attributes = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(ATTRS_EXTENSION_Q))
+ final ContainerNode attributes = Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(ATTRS_EXTENSION_Q))
.addChild(Builders.containerBuilder().withNodeIdentifier(ORIGIN_NID)
- .addChild(Builders.leafBuilder().withNodeIdentifier(ORIGIN_VALUE_NID).withValue("igp").build()).build())
+ .addChild(Builders.leafBuilder().withNodeIdentifier(ORIGIN_VALUE_NID)
+ .withValue("igp").build()).build())
.addChild(Builders.containerBuilder().withNodeIdentifier(AS_PATH_NID)
.addChild(Builders.unkeyedListBuilder().withNodeIdentifier(SEGMENTS_NID).build()).build())
.addChild(Builders.containerBuilder().withNodeIdentifier(ATOMIC_NID).build()).build();
return ImmutableContainerNodeBuilder.create().withNodeIdentifier(ROUTE_ATTRIBUTES_IDENTIFIER)
.withChild(attributes).build();
}
+
+ protected Map<YangInstanceIdentifier, Long> collectInfo() {
+ return this.yiichanges.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
+ }
}