summaryrefslogtreecommitdiffstats
path: root/mpls
diff options
context:
space:
mode:
Diffstat (limited to 'mpls')
-rw-r--r--mpls/impl/src/main/java/io/fd/hc2vpp/mpls/ImposeAndForwardWriter.java22
-rw-r--r--mpls/impl/src/test/java/io/fd/hc2vpp/mpls/ImposeAndForwardTest.java23
2 files changed, 35 insertions, 10 deletions
diff --git a/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/ImposeAndForwardWriter.java b/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/ImposeAndForwardWriter.java
index 14053b63d..861ab9ddf 100644
--- a/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/ImposeAndForwardWriter.java
+++ b/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/ImposeAndForwardWriter.java
@@ -103,12 +103,15 @@ final class ImposeAndForwardWriter implements LspWriter, Ipv4Translator {
private String translate(@Nonnull final SimplePath path, @Nonnull final IpAddDelRoute request) {
final IpAddress nextHop = path.getNextHop();
- checkArgument(nextHop != null, "Configuring impose-and-forward, but next-hop is missing.");
// TODO(HC2VPP-264): add support for mpls + v6
- final Ipv4Address address = nextHop.getIpv4Address();
- checkArgument(address != null, "Only IPv4 next-hop address is supported.");
- request.nextHopAddress = ipv4AddressNoZoneToArray(address.getValue());
+ if (nextHop != null) {
+ final Ipv4Address address = nextHop.getIpv4Address();
+ checkArgument(address != null, "Only IPv4 next-hop address is supported.");
+ request.nextHopAddress = ipv4AddressNoZoneToArray(address.getValue());
+ } else {
+ request.nextHopAddress = new byte[0];
+ }
final MplsLabel outgoingLabel = path.getOutgoingLabel();
checkArgument(outgoingLabel != null, "Configuring impose-and-forward, but outgoing-label is missing.");
@@ -122,12 +125,15 @@ final class ImposeAndForwardWriter implements LspWriter, Ipv4Translator {
checkArgument(pathList.getPaths() != null && pathList.getPaths().size() == 1, "Only single path is supported");
final Paths paths = pathList.getPaths().get(0);
final IpAddress nextHop = paths.getNextHop();
- checkArgument(nextHop != null, "Configuring impose-and-forward, but next-hop is missing.");
// TODO(HC2VPP-264): add support for mpls + v6
- final Ipv4Address address = nextHop.getIpv4Address();
- checkArgument(address != null, "Only IPv4 next-hop address is supported.");
- request.nextHopAddress = ipv4AddressNoZoneToArray(address.getValue());
+ if (nextHop != null) {
+ final Ipv4Address address = nextHop.getIpv4Address();
+ checkArgument(address != null, "Only IPv4 next-hop address is supported.");
+ request.nextHopAddress = ipv4AddressNoZoneToArray(address.getValue());
+ } else {
+ request.nextHopAddress = new byte[0];
+ }
final List<MplsLabel> labels = paths.getOutgoingLabels();
final int numberOfLabels = labels.size();
diff --git a/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/ImposeAndForwardTest.java b/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/ImposeAndForwardTest.java
index a4689a74c..c1ced8e1d 100644
--- a/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/ImposeAndForwardTest.java
+++ b/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/ImposeAndForwardTest.java
@@ -32,6 +32,7 @@ import java.util.Arrays;
import java.util.Collections;
import org.junit.Test;
import org.mockito.Mock;
+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.IpAddressBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310.Mpls1;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310.StaticLspConfig;
@@ -68,6 +69,10 @@ public class ImposeAndForwardTest extends WriterCustomizerTest implements ByteDa
private StaticLspCustomizer customizer;
private static StaticLsp getSimpleLsp(final long label) {
+ return getSimpleLsp(label, IpAddressBuilder.getDefaultInstance("5.6.7.8"));
+ }
+ private static StaticLsp getSimpleLsp(final long label,
+ final IpAddress nextHop) {
return new StaticLspBuilder()
.setName(LSP_NAME)
.setConfig(new ConfigBuilder()
@@ -78,7 +83,7 @@ public class ImposeAndForwardTest extends WriterCustomizerTest implements ByteDa
)
.setOperation(StaticLspConfig.Operation.ImposeAndForward)
.setOutSegment(new SimplePathBuilder()
- .setNextHop(IpAddressBuilder.getDefaultInstance("5.6.7.8"))
+ .setNextHop(nextHop)
.setOutgoingInterface(IF_NAME)
.setOutgoingLabel(new MplsLabel(label))
.build())
@@ -122,6 +127,12 @@ public class ImposeAndForwardTest extends WriterCustomizerTest implements ByteDa
}
@Test
+ public void testWriteSimpleWithoutNextHop() throws WriteFailedException {
+ customizer.writeCurrentAttributes(IID, getSimpleLsp((long) LABEL, null), writeContext);
+ verify(jvpp).ipAddDelRoute(getRequestForSimpleLsp(true, new byte[0]));
+ }
+
+ @Test
public void testWriteComplex() throws WriteFailedException {
customizer.writeCurrentAttributes(IID, COMPLEX_LSP, writeContext);
verify(jvpp).ipAddDelRoute(getRequestForComplexLsp(true));
@@ -151,14 +162,22 @@ public class ImposeAndForwardTest extends WriterCustomizerTest implements ByteDa
return getRequestForSimpleLsp(add, LABEL);
}
+ private IpAddDelRoute getRequestForSimpleLsp(final boolean add, final byte[] nextHop) {
+ return getRequestForSimpleLsp(add, LABEL, nextHop);
+ }
+
private IpAddDelRoute getRequestForSimpleLsp(final boolean add, final int label) {
+ return getRequestForSimpleLsp(add, label, new byte[] {5, 6, 7, 8});
+ }
+
+ private IpAddDelRoute getRequestForSimpleLsp(final boolean add, final int label, final byte[] nextHop) {
final IpAddDelRoute request = new IpAddDelRoute();
request.nextHopSwIfIndex = IF_INDEX;
request.isAdd = booleanToByte(add);
request.nextHopWeight = 1;
request.dstAddressLength = (byte) 24;
request.dstAddress = new byte[] {1, 2, 3, 4};
- request.nextHopAddress = new byte[] {5, 6, 7, 8};
+ request.nextHopAddress = nextHop;
request.nextHopNOutLabels = 1;
request.nextHopViaLabel = LspWriter.MPLS_LABEL_INVALID;
request.nextHopOutLabelStack = new int[] {label};