Search in sources :

Example 46 with Ipv4

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.identifiers.tlv.lsp.identifiers.address.family.ipv4._case.Ipv4 in project openflowplugin by opendaylight.

the class SalToOfSetNwDstActionV10Case method process.

@Nonnull
@Override
public Optional<Action> process(@Nonnull final SetNwDstActionCase source, final ActionConvertorData data, ConvertorExecutor convertorExecutor) {
    final ActionBuilder builder = new ActionBuilder();
    final Address address = source.getSetNwDstAction().getAddress();
    if (address instanceof Ipv4) {
        // FIXME use of substring should be removed and OF models should distinguish where
        // FIXME to use Ipv4Prefix (with mask) and where to use Ipv4Address (without mask)
        String ipAddress = ((Ipv4) address).getIpv4Address().getValue();
        ipAddress = ipAddress.substring(0, ipAddress.indexOf("/"));
        Ipv4Address result = new Ipv4Address(ipAddress);
        SetNwDstCaseBuilder setNwDstCaseBuilder = new SetNwDstCaseBuilder();
        SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
        setNwDstActionBuilder.setIpAddress(result);
        setNwDstCaseBuilder.setSetNwDstAction(setNwDstActionBuilder.build());
        builder.setActionChoice(setNwDstCaseBuilder.build());
    } else {
        throw new IllegalArgumentException("Address is not supported by OF-1.0: " + address.getClass().getName());
    }
    return Optional.of(builder.build());
}
Also used : ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder) SetNwDstActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.dst._case.SetNwDstActionBuilder) Address(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) SetNwDstActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.dst._case.SetNwDstActionBuilder) Ipv4(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4) SetNwDstCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwDstCaseBuilder) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Nonnull(javax.annotation.Nonnull)

Example 47 with Ipv4

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.identifiers.tlv.lsp.identifiers.address.family.ipv4._case.Ipv4 in project openflowplugin by opendaylight.

the class SalToOfSetNwSrcActionV10Case method process.

@Nonnull
@Override
public Optional<Action> process(@Nonnull final SetNwSrcActionCase source, final ActionConvertorData data, ConvertorExecutor convertorExecutor) {
    final ActionBuilder builder = new ActionBuilder();
    final Address address = source.getSetNwSrcAction().getAddress();
    if (address instanceof Ipv4) {
        // FIXME use of substring should be removed and OF models should distinguish where
        // FIXME to use Ipv4Prefix (with mask) and where to use Ipv4Address (without mask)
        String ipAddress = ((Ipv4) address).getIpv4Address().getValue();
        ipAddress = ipAddress.substring(0, ipAddress.indexOf("/"));
        Ipv4Address result = new Ipv4Address(ipAddress);
        SetNwSrcCaseBuilder nwSrcCaseBuilder = new SetNwSrcCaseBuilder();
        SetNwSrcActionBuilder nwSrcBuilder = new SetNwSrcActionBuilder();
        nwSrcBuilder.setIpAddress(new Ipv4Address(result));
        nwSrcCaseBuilder.setSetNwSrcAction(nwSrcBuilder.build());
        builder.setActionChoice(nwSrcCaseBuilder.build());
    } else {
        throw new IllegalArgumentException("Address is not supported by OF-1.0: " + address.getClass().getName());
    }
    return Optional.of(builder.build());
}
Also used : SetNwSrcActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.src._case.SetNwSrcActionBuilder) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder) Address(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Ipv4(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4) SetNwSrcActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.src._case.SetNwSrcActionBuilder) SetNwSrcCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwSrcCaseBuilder) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Nonnull(javax.annotation.Nonnull)

Example 48 with Ipv4

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.identifiers.tlv.lsp.identifiers.address.family.ipv4._case.Ipv4 in project openflowplugin by opendaylight.

the class MatchV10Convertor method convertL3Ipv4SrcMatch.

/**
 * Method splits the IP address and its mask and set their respective values in MatchV10Builder instance.
 * Wildcard value of the IP mask will be determined by Openflow java encoding library.
 *
 * @param matchBuilder match builder
 * @param ipv4         ip v4 match
 */
private static void convertL3Ipv4SrcMatch(final MatchV10Builder matchBuilder, final Ipv4Match ipv4) {
    if (ipv4.getIpv4Source() != null) {
        Iterator<String> addressParts = IpConversionUtil.PREFIX_SPLITTER.split(ipv4.getIpv4Source().getValue()).iterator();
        Ipv4Address ipv4Address = new Ipv4Address(addressParts.next());
        int prefix = buildPrefix(addressParts);
        matchBuilder.setNwSrc(ipv4Address);
        matchBuilder.setNwSrcMask((short) prefix);
    }
}
Also used : Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Example 49 with Ipv4

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.identifiers.tlv.lsp.identifiers.address.family.ipv4._case.Ipv4 in project openflowplugin by opendaylight.

the class SetNwSrcActionSerializerTest method testSerialize.

@Test
public void testSerialize() throws Exception {
    final Ipv4 address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("192.168.76.2/32")).build();
    final Action action = new SetNwSrcActionCaseBuilder().setSetNwSrcAction(new SetNwSrcActionBuilder().setAddress(address).build()).build();
    assertAction(action, out -> {
        byte[] addressBytes = new byte[4];
        out.readBytes(addressBytes);
        assertArrayEquals(addressBytes, new byte[] { (byte) 192, (byte) 168, 76, 2 });
    });
}
Also used : SetNwSrcActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action) Ipv4(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4) SetNwSrcActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder) Ipv4Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) Test(org.junit.Test)

Example 50 with Ipv4

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.identifiers.tlv.lsp.identifiers.address.family.ipv4._case.Ipv4 in project lispflowmapping by opendaylight.

the class MapRequestUtilTest method selectItrRlocTest_Ipv4.

/**
 * Tests {@link MapRequestUtil#selectItrRloc} method with Ipv4.
 */
@Test
public void selectItrRlocTest_Ipv4() {
    final ItrRlocBuilder itrRloc = new ItrRlocBuilder().setRloc(new RlocBuilder().setAddress(IPV4_ADDRESS).build());
    final MapRequest request = new MapRequestBuilder().setItrRloc(Lists.newArrayList(itrRloc.build())).build();
    // expected result
    InetAddress expectedResult = InetAddresses.forString(IPV4_STRING);
    // result
    InetAddress result = MapRequestUtil.selectItrRloc(request);
    assertEquals(expectedResult, result);
}
Also used : MapRequest(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest) ItrRlocBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder) RlocBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder) ItrRlocBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder) MapRequestBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestmessage.MapRequestBuilder) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)89 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)35 ArrayList (java.util.ArrayList)32 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)23 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)22 ByteBuf (io.netty.buffer.ByteBuf)21 Ipv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder)19 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)18 Ipv6MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder)17 BigInteger (java.math.BigInteger)16 IpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder)15 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)14 EthernetMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder)14 Icmpv6MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder)14 TunnelIpv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4MatchBuilder)12 EtherType (org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType)11 EthernetTypeBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder)11 MatchEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry)11 MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)10 PortNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber)10