import static io.fd.hc2vpp.bgp.prefix.sid.MplsRouteRequestProducer.MPLS_LABEL_INVALID;
import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.hc2vpp.common.translate.util.MplsLabelTranslator;
import io.fd.vpp.jvpp.core.dto.IpAddDelRoute;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import java.util.List;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
// TODO(HC2VPP-271): add support for special labels, e.g. implicit null (for PHP).
// Push label received via BGP on packets destined to the prefix it was assigned to:
- request.nextHopOutLabelStack = new int[] {label};
+ request.nextHopOutLabelStack = new FibMplsLabel[] {MplsLabelTranslator.INSTANCE.translate(label)};
request.nextHopNOutLabels = 1;
}
}
import static com.google.common.base.Preconditions.checkArgument;
import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.hc2vpp.common.translate.util.MplsLabelTranslator;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDel;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import java.util.List;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
return request;
}
- final class Impl implements Ipv4Translator {
+ final class Impl implements Ipv4Translator, MplsLabelTranslator {
private static MplsRouteAddDel mplsRouteAddDel(final boolean isAdd) {
final MplsRouteAddDel request = new MplsRouteAddDel();
request.mrIsAdd = Ipv4Translator.INSTANCE.booleanToByte(isAdd);
// TODO(HC2VPP-271): add support for special labels, e.g. implicit null (for PHP).
// swap one label to another
- request.mrNextHopOutLabelStack = new int[] {label};
+ request.mrNextHopOutLabelStack = new FibMplsLabel[] {MplsLabelTranslator.INSTANCE.translate(label)};
request.mrNextHopNOutLabels = 1;
}
}
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDel;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDelReply;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
request.mrLabel = 16102;
- request.mrNextHopOutLabelStack = new int[] {16101};
+ final FibMplsLabel mplsLabel = new FibMplsLabel();
+ mplsLabel.label = 16101;
+ request.mrNextHopOutLabelStack = new FibMplsLabel[] {mplsLabel};
request.mrNextHopNOutLabels = 1;
request.mrEos = booleanToByte(isEos);
request.nextHopAddress = new byte[] {5, 6, 7, 8};
request.nextHopSwIfIndex = -1;
- request.nextHopOutLabelStack = new int[] {16101};
+ final FibMplsLabel mplsLabel = new FibMplsLabel();
+ mplsLabel.label = 16101;
+ request.nextHopOutLabelStack = new FibMplsLabel[] {mplsLabel};
request.nextHopNOutLabels = 1;
return request;
}
import static com.google.common.base.Preconditions.checkArgument;
import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.hc2vpp.common.translate.util.MplsLabelTranslator;
import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.core.dto.IpAddDelRoute;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import java.util.List;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
*
* @see <a href="https://git.fd.io/vpp/tree/src/vnet/ip/ip.api">ip_add_del_route</a> definition
*/
-final class ImposeAndForwardWriter implements LspWriter, Ipv4Translator {
+final class ImposeAndForwardWriter implements LspWriter, Ipv4Translator, MplsLabelTranslator {
private final FutureJVppCore vppApi;
private final NamingContext interfaceContext;
final MplsLabel outgoingLabel = path.getOutgoingLabel();
checkArgument(outgoingLabel != null, "Configuring impose-and-forward, but outgoing-label is missing.");
- request.nextHopOutLabelStack = new int[] {outgoingLabel.getValue().intValue()};
+ request.nextHopOutLabelStack = new FibMplsLabel[] {translate(outgoingLabel.getValue())};
request.nextHopNOutLabels = 1;
return path.getOutgoingInterface();
checkArgument(numberOfLabels > 0 && numberOfLabels < MAX_LABELS, "Number of labels (%s) not in range (0, %s].",
numberOfLabels, MAX_LABELS, numberOfLabels);
request.nextHopNOutLabels = (byte) numberOfLabels;
- request.nextHopOutLabelStack = labels.stream().mapToInt(label -> label.getValue().intValue()).toArray();
+ request.nextHopOutLabelStack =
+ labels.stream().map(label -> translate(label.getValue())).toArray(FibMplsLabel[]::new);
return paths.getOutgoingInterface();
}
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDel;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310.StaticLspConfig;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310._static.lsp.Config;
request.mrNextHopProto = IPV4_PROTOCOL;
request.mrNextHopWeight = 1;
request.mrNextHop = new byte[0]; // no next hop since we POP
- request.mrNextHopOutLabelStack = new int[0]; // no new labels
+ request.mrNextHopOutLabelStack = new FibMplsLabel[0]; // no new labels
request.mrNextHopSwIfIndex = -1;
request.mrNextHopViaLabel = MPLS_LABEL_INVALID;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDel;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310.StaticLspConfig;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310._static.lsp.Config;
request.mrNextHopProto = MPLS_PROTOCOL;
request.mrNextHopWeight = 1;
request.mrNextHop = new byte[0]; // no next hop since we POP
- request.mrNextHopOutLabelStack = new int[0]; // no new labels
+ request.mrNextHopOutLabelStack = new FibMplsLabel[0]; // no new labels
request.mrNextHopSwIfIndex = -1;
request.mrNextHopViaLabel = MPLS_LABEL_INVALID;
import static com.google.common.base.Preconditions.checkArgument;
import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.hc2vpp.common.translate.util.MplsLabelTranslator;
import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDel;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import javax.annotation.Nonnull;
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;
*
* @see <a href="https://git.fd.io/vpp/tree/src/vnet/mpls/mpls.api">mpls_route_add_del</a> definition
*/
-final class MplsSwapWriter implements LspWriter, Ipv4Translator, MplsInSegmentTranslator {
+final class MplsSwapWriter implements LspWriter, Ipv4Translator, MplsInSegmentTranslator, MplsLabelTranslator {
private final FutureJVppCore vppApi;
private final NamingContext interfaceContext;
final MplsLabel outgoingLabel = path.getOutgoingLabel();
checkArgument(outgoingLabel != null, "Configuring swap-and-forward, but outgoing-label is missing.");
- request.mrNextHopOutLabelStack = new int[] {outgoingLabel.getValue().intValue()};
+ request.mrNextHopOutLabelStack = new FibMplsLabel[] {translate(outgoingLabel.getValue())};
request.mrNextHopNOutLabels = 1;
final String outgoingInterface = path.getOutgoingInterface();
import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
+import io.fd.hc2vpp.common.translate.util.MplsLabelTranslator;
import io.fd.hc2vpp.common.translate.util.NamingContext;
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.future.FutureJVppCoreFacade;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Test;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev170227.MplsLabel;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-public class ImposeAndForwardTest extends WriterCustomizerTest implements ByteDataTranslator {
+public class ImposeAndForwardTest extends WriterCustomizerTest implements ByteDataTranslator, MplsLabelTranslator {
private static final String IF_NAME = "local0";
private static final int IF_INDEX = 123;
request.nextHopAddress = nextHop;
request.nextHopNOutLabels = 1;
request.nextHopViaLabel = LspWriter.MPLS_LABEL_INVALID;
- request.nextHopOutLabelStack = new int[] {label};
+ request.nextHopOutLabelStack = new FibMplsLabel[] {translate(label)};
return request;
}
request.nextHopAddress = new byte[] {10, 10, 12, 2};
request.nextHopNOutLabels = 2;
request.nextHopViaLabel = LspWriter.MPLS_LABEL_INVALID;
- request.nextHopOutLabelStack = new int[] {102, 104};
+ request.nextHopOutLabelStack = new FibMplsLabel[] {translate(102), translate(104)};
return request;
}
}
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDel;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDelReply;
import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import org.junit.Test;
import org.mockito.Mock;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310.Mpls1;
request.mrNextHop = new byte[0]; // POP, so no next hop
request.mrNextHopSwIfIndex = -1; // this is what CLI is doing
request.mrNextHopViaLabel = LspWriter.MPLS_LABEL_INVALID; // default value used by make test
- request.mrNextHopOutLabelStack = new int[0];
+ request.mrNextHopOutLabelStack = new FibMplsLabel[0];
return request;
}
}
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDel;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDelReply;
import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import org.junit.Test;
import org.mockito.Mock;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310.Mpls1;
request.mrNextHop = new byte[0]; // POP, so no next hop
request.mrNextHopSwIfIndex = -1; // this is what CLI is doing
request.mrNextHopViaLabel = LspWriter.MPLS_LABEL_INVALID; // default value used by make test
- request.mrNextHopOutLabelStack = new int[0];
+ request.mrNextHopOutLabelStack = new FibMplsLabel[0];
return request;
}
}
import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
+import io.fd.hc2vpp.common.translate.util.MplsLabelTranslator;
import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDel;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDelReply;
import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import org.junit.Test;
import org.mockito.Mock;
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.routing.types.rev170227.MplsLabel;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-public class SwapAndForwardTest extends WriterCustomizerTest implements ByteDataTranslator {
+public class SwapAndForwardTest extends WriterCustomizerTest implements ByteDataTranslator, MplsLabelTranslator {
private static final String IF_NAME = "local0";
private static final int IF_INDEX = 123;
request.mrNextHopSwIfIndex = IF_INDEX;
request.mrNextHopViaLabel = LspWriter.MPLS_LABEL_INVALID; // default value used by make test
request.mrNextHopNOutLabels = 1;
- request.mrNextHopOutLabelStack = new int[] {OUT_LABEL};
+ request.mrNextHopOutLabelStack = new FibMplsLabel[] {translate(OUT_LABEL)};
return request;
}
}
--- /dev/null
+/*
+ * Copyright (c) 2018 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.common.translate.util;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
+import javax.annotation.Nonnull;
+
+/**
+ * Utility for Translating between different representations of MPLS label.
+ */
+public interface MplsLabelTranslator {
+ /**
+ * Make available also from static context.
+ */
+ MplsLabelTranslator INSTANCE = new MplsLabelTranslator() {
+ };
+
+ /**
+ * Builds {@link FibMplsLabel} from its YANG representation.
+ *
+ * @param label YANG representation of MPLS Label
+ * @return VPP representation of MPLS label
+ */
+ default FibMplsLabel translate(@Nonnull final Long label) {
+ checkNotNull(label, "MPLS label should not be null");
+ return translate(label.intValue());
+ }
+
+ /**
+ * Builds {@link FibMplsLabel} from int value.
+ *
+ * @param label MPLS Label value
+ * @return VPP representation of MPLS label
+ */
+ default FibMplsLabel translate(final int label) {
+ final FibMplsLabel fibMplsLabel = new FibMplsLabel();
+ fibMplsLabel.label = label;
+ return fibMplsLabel;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.common.translate.util;
+
+import static org.junit.Assert.assertEquals;
+
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
+import org.junit.Test;
+
+public class MplsLabelTranslatorTest implements MplsLabelTranslator {
+ @Test
+ public void testTranslateLong() {
+ final int expectedLabel = 1048575;
+ final FibMplsLabel expected = new FibMplsLabel();
+ expected.label = expectedLabel;
+ assertEquals(expected, translate(Long.valueOf(1048575)));
+ }
+ @Test
+ public void testTranslateInt() {
+ final int expectedLabel = 11;
+ final FibMplsLabel expected = new FibMplsLabel();
+ expected.label = expectedLabel;
+ assertEquals(expected, translate(expectedLabel));
+ }
+
+}