summaryrefslogtreecommitdiffstats
path: root/bgp/bgp-prefix-sid/src/test/java/io/fd
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2017-12-22 15:08:19 +0100
committerMarek Gradzki <mgradzki@cisco.com>2017-12-22 15:22:08 +0100
commit9a25f286116d8ecd75dcc03a2ef5f7b3d20fc24e (patch)
treed5e6f47acaba0f9b748763cf7f9c7eb3809787c9 /bgp/bgp-prefix-sid/src/test/java/io/fd
parent6bb01993fda9b927923ba351d5509ed741ad616e (diff)
HC2VPP-268: add non-eos MPLS and IP FIB entries
VPP manages separate eos and non-eos forwarding chains, so non-eos FIB entry is also needed. Imposing received outgoing label on IP packets is also required as described in https://tools.ietf.org/html/draft-ietf-idr-bgp-prefix-sid-07#page-10 and https://tools.ietf.org/html/draft-ietf-spring-segment-routing-msdc-08#section-4.2.2 Change-Id: Idb91dc44beb64f614f02a95ef0f4b8495c6aeb69 Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'bgp/bgp-prefix-sid/src/test/java/io/fd')
-rw-r--r--bgp/bgp-prefix-sid/src/test/java/io/fd/hc2vpp/bgp/prefix/sid/BgpPrefixSidMplsWriterTest.java105
1 files changed, 78 insertions, 27 deletions
diff --git a/bgp/bgp-prefix-sid/src/test/java/io/fd/hc2vpp/bgp/prefix/sid/BgpPrefixSidMplsWriterTest.java b/bgp/bgp-prefix-sid/src/test/java/io/fd/hc2vpp/bgp/prefix/sid/BgpPrefixSidMplsWriterTest.java
index 36df877c1..93b6ac66c 100644
--- a/bgp/bgp-prefix-sid/src/test/java/io/fd/hc2vpp/bgp/prefix/sid/BgpPrefixSidMplsWriterTest.java
+++ b/bgp/bgp-prefix-sid/src/test/java/io/fd/hc2vpp/bgp/prefix/sid/BgpPrefixSidMplsWriterTest.java
@@ -18,7 +18,11 @@ package io.fd.hc2vpp.bgp.prefix.sid;
import static io.fd.hc2vpp.bgp.prefix.sid.BgpPrefixSidMplsWriter.MPLS_LABEL_INVALID;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
@@ -26,6 +30,8 @@ import com.google.common.collect.Lists;
import io.fd.hc2vpp.common.test.util.FutureProducer;
import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.core.dto.IpAddDelRoute;
+import io.fd.vpp.jvpp.core.dto.IpAddDelRouteReply;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDel;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDelReply;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
@@ -33,8 +39,10 @@ import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
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.Ipv4AddressNoZone;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.LabeledUnicastRoutes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.Srgb;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.LabelStackBuilder;
@@ -80,15 +88,25 @@ public class BgpPrefixSidMplsWriterTest implements FutureProducer, ByteDataTrans
.child(LabeledUnicastRoute.class, new LabeledUnicastRouteKey(pathId, routeKey));
}
- private static LabeledUnicastRoute route(final String routeKey, final PathId pathId,
- final Ipv4Address nextHopAddress,
- final BgpPrefixSid bgpPrefixSid) {
+ private static LabeledUnicastRoute route(final PathId pathId, final String routeKey) {
+ final Ipv4Address nextHopAddress = new Ipv4AddressNoZone("5.6.7.8");
+
+ final BgpPrefixSid bgpPrefixSid = new BgpPrefixSidBuilder()
+ .setBgpPrefixSidTlvs(
+ Lists.newArrayList(
+ labelIndexTlv(102L),
+ originatorSrgbTlv(16000, 800)
+ ))
+ .build();
+
final Ipv4NextHopCase nextHop =
new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(nextHopAddress).build())
.build();
+ final IpPrefix prefix = new IpPrefix(new Ipv4Prefix("1.2.3.4/24"));
return new LabeledUnicastRouteBuilder()
.setKey(new LabeledUnicastRouteKey(pathId, routeKey))
.setPathId(pathId)
+ .setPrefix(prefix)
.setAttributes(new AttributesBuilder()
.setCNextHop(nextHop)
.setBgpPrefixSid(bgpPrefixSid)
@@ -106,14 +124,7 @@ public class BgpPrefixSidMplsWriterTest implements FutureProducer, ByteDataTrans
.build();
}
- @Before
- public void setUp() {
- initMocks(this);
- writer = new BgpPrefixSidMplsWriter(vppApi);
- when(vppApi.mplsRouteAddDel(any())).thenReturn(future(new MplsRouteAddDelReply()));
- }
-
- private BgpPrefixSidTlvs originatorSrgbTlv(final long base, final long range) {
+ private static BgpPrefixSidTlvs originatorSrgbTlv(final long base, final long range) {
return new BgpPrefixSidTlvsBuilder()
.setBgpPrefixSidTlv(new LuOriginatorSrgbTlvBuilder()
.setSrgbValue(Collections.singletonList(new SrgbValueBuilder()
@@ -124,27 +135,49 @@ public class BgpPrefixSidMplsWriterTest implements FutureProducer, ByteDataTrans
.build();
}
+ @Before
+ public void setUp() {
+ initMocks(this);
+ writer = new BgpPrefixSidMplsWriter(vppApi);
+ when(vppApi.mplsRouteAddDel(any())).thenReturn(future(new MplsRouteAddDelReply()));
+ when(vppApi.ipAddDelRoute(any())).thenReturn(future(new IpAddDelRouteReply()));
+ }
+
@Test
public void testCreate() throws WriteFailedException.CreateFailedException {
final String routeKey = "route-key";
final PathId pathId = new PathId(123L);
- final Ipv4Address nextHopAddress = new Ipv4AddressNoZone("5.6.7.8");
+ writer.create(id(pathId, routeKey), route(pathId, routeKey));
- final BgpPrefixSid bgpPrefixSid = new BgpPrefixSidBuilder()
- .setBgpPrefixSidTlvs(
- Lists.newArrayList(
- labelIndexTlv(102L),
- originatorSrgbTlv(16000, 800)
- ))
- .build();
- writer.create(
- id(pathId, routeKey),
- route(routeKey, pathId, nextHopAddress, bgpPrefixSid)
- );
- verifyRequest(true);
+ verify(vppApi, times(2)).mplsRouteAddDel(any());
+ // BgpPrefixSidMplsWriter.create reuses DTO for two calls for performance reasons, but mockito
+ // (InOrder, ArgumentCaptor) works with object references, not values. We are a bit too lazy to use thenAnswer,
+ // so checking just second invocation:
+ verify(vppApi, atLeastOnce()).mplsRouteAddDel(getRequest(true, true));
+
+ verify(vppApi).ipAddDelRoute(getRequest(true));
+ }
+
+ @Test
+ public void testDelete() throws WriteFailedException.DeleteFailedException {
+ final String routeKey = "route-key";
+ final PathId pathId = new PathId(123L);
+ writer.delete(id(pathId, routeKey), route(pathId, routeKey));
+
+ verify(vppApi, times(2)).mplsRouteAddDel(any());
+ verify(vppApi, atLeastOnce()).mplsRouteAddDel(getRequest(false, true));
+ verify(vppApi).ipAddDelRoute(getRequest(false));
+ }
+
+ @Test(expected = WriteFailedException.UpdateFailedException.class)
+ public void testUpdate() throws WriteFailedException.UpdateFailedException {
+ final String routeKey = "route-key";
+ final PathId pathId = new PathId(123L);
+ writer.update(id(pathId, routeKey), mock(LabeledUnicastRoute.class), mock(LabeledUnicastRoute.class));
+ verifyZeroInteractions(vppApi);
}
- private void verifyRequest(boolean isAdd) {
+ private MplsRouteAddDel getRequest(boolean isAdd, boolean isEos) {
final MplsRouteAddDel request = new MplsRouteAddDel();
request.mrIsAdd = booleanToByte(isAdd);
request.mrClassifyTableIndex = -1;
@@ -159,7 +192,25 @@ public class BgpPrefixSidMplsWriterTest implements FutureProducer, ByteDataTrans
request.mrNextHopOutLabelStack = new int[] {16101};
request.mrNextHopNOutLabels = 1;
- request.mrEos = 1;
- verify(vppApi).mplsRouteAddDel(request);
+ request.mrEos = booleanToByte(isEos);
+ return request;
+ }
+
+ private IpAddDelRoute getRequest(boolean isAdd) {
+ final IpAddDelRoute request = new IpAddDelRoute();
+ request.isAdd = booleanToByte(isAdd);
+ request.classifyTableIndex = -1;
+ request.nextHopWeight = 1;
+ request.nextHopViaLabel = MPLS_LABEL_INVALID;
+
+ request.dstAddressLength = 24;
+ request.dstAddress = new byte[] {1, 2, 3, 4};
+
+ request.nextHopAddress = new byte[] {5, 6, 7, 8};
+ request.nextHopSwIfIndex = -1;
+
+ request.nextHopOutLabelStack = new int[] {16101};
+ request.nextHopNOutLabels = 1;
+ return request;
}
}