Search in sources :

Example 46 with Ipv4Prefix

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix in project openflowplugin by opendaylight.

the class ArpSourceTransportAddressEntryDeserializer method deserializeEntry.

@Override
public void deserializeEntry(ByteBuf message, MatchBuilder builder) {
    final boolean hasMask = processHeader(message);
    final Layer3Match layer3Match = builder.getLayer3Match();
    final Ipv4Prefix prefix = readPrefix(message, hasMask);
    if (Objects.isNull(layer3Match)) {
        builder.setLayer3Match(new ArpMatchBuilder().setArpSourceTransportAddress(prefix).build());
    } else if (ArpMatch.class.isInstance(layer3Match) && Objects.isNull(ArpMatch.class.cast(layer3Match).getArpSourceTransportAddress())) {
        builder.setLayer3Match(new ArpMatchBuilder(ArpMatch.class.cast(layer3Match)).setArpSourceTransportAddress(prefix).build());
    } else {
        throwErrorOnMalformed(builder, "layer3Match", "arpSourceTransportAddress");
    }
}
Also used : Layer3Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match) ArpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) ArpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder)

Example 47 with Ipv4Prefix

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix in project openflowplugin by opendaylight.

the class AbstractMatchEntryDeserializer method readPrefix.

/**
 * Read Ipv4Prefix from message.
 * @param message buffered message
 * @param hasMask determines if prefix has mask or not
 * @return IPv4 prefix
 */
protected static Ipv4Prefix readPrefix(ByteBuf message, boolean hasMask) {
    final Ipv4Address address = ByteBufUtils.readIetfIpv4Address(message);
    int mask = 32;
    if (hasMask) {
        mask = IpConversionUtil.countBits(OxmDeserializerHelper.convertMask(message, EncodeConstants.GROUPS_IN_IPV4_ADDRESS));
    }
    return IpConversionUtil.createPrefix(address, mask);
}
Also used : Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Example 48 with Ipv4Prefix

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix in project openflowplugin by opendaylight.

the class ArpTargetTransportAddressEntryDeserializerTest method deserializeEntry.

@Test
public void deserializeEntry() throws Exception {
    final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
    final Ipv4Prefix arpTargetTransportAddress = new Ipv4Prefix("192.168.0.0/24");
    final Ipv4Prefix arpTargetTransportAddressNoMask = new Ipv4Prefix("192.168.0.0/32");
    writeHeader(in, false);
    Iterator<String> addressParts = IpConversionUtil.splitToParts(arpTargetTransportAddressNoMask);
    in.writeBytes(IetfInetUtil.INSTANCE.ipv4AddressBytes(new Ipv4Address(addressParts.next())));
    assertEquals(arpTargetTransportAddressNoMask.getValue(), ArpMatch.class.cast(deserialize(in).getLayer3Match()).getArpTargetTransportAddress().getValue());
    assertEquals(0, in.readableBytes());
    writeHeader(in, true);
    addressParts = IpConversionUtil.splitToParts(arpTargetTransportAddress);
    in.writeBytes(IetfInetUtil.INSTANCE.ipv4AddressBytes(new Ipv4Address(addressParts.next())));
    in.writeBytes(MatchConvertorUtil.extractIpv4Mask(addressParts));
    final Ipv4Prefix desAddress = ArpMatch.class.cast(deserialize(in).getLayer3Match()).getArpTargetTransportAddress();
    assertEquals(arpTargetTransportAddress.getValue(), desAddress.getValue());
    assertEquals(0, in.readableBytes());
}
Also used : ArpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch) ByteBuf(io.netty.buffer.ByteBuf) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Test(org.junit.Test)

Example 49 with Ipv4Prefix

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix in project openflowplugin by opendaylight.

the class Ipv4SourceEntryDeserializerTest method deserializeEntry.

@Test
public void deserializeEntry() throws Exception {
    final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
    final Ipv4Prefix address = new Ipv4Prefix("192.168.72.0/24");
    final Iterator<String> addressParts = IpConversionUtil.splitToParts(address);
    writeHeader(in, true);
    in.writeBytes(IetfInetUtil.INSTANCE.ipv4AddressBytes(new Ipv4Address(addressParts.next())));
    in.writeBytes(MatchConvertorUtil.extractIpv4Mask(addressParts));
    final Ipv4Match match = Ipv4Match.class.cast(deserialize(in).getLayer3Match());
    assertEquals(address.getValue(), match.getIpv4Source().getValue());
    assertEquals(0, in.readableBytes());
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) Ipv4Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Test(org.junit.Test)

Example 50 with Ipv4Prefix

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix in project openflowplugin by opendaylight.

the class SetNwDstActionSerializerTest 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 SetNwDstActionCaseBuilder().setSetNwDstAction(new SetNwDstActionBuilder().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 : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action) SetNwDstActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder) Ipv4(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4) SetNwDstActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder) 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)

Aggregations

Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)152 Test (org.junit.Test)88 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)40 ArrayList (java.util.ArrayList)37 ByteBuf (io.netty.buffer.ByteBuf)36 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)33 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)33 Ipv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder)33 EthernetMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder)22 ArpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder)20 TunnelIpv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4MatchBuilder)20 Ipv4Match (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match)18 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder)18 Ipv6MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder)16 IpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder)15 SetNwSrcActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder)14 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder)14 EthernetTypeBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder)14 Ipv6Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix)13 SetNwDstActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder)12