use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix in project openflowplugin by opendaylight.
the class MatchNormalizationUtilTest method normalizeIpv4Match.
@Test
public void normalizeIpv4Match() {
final String source = "192.168.1.2/24";
final String destination = "192.168.2.2/24";
final MatchBuilder matchBuilder = MatchNormalizationUtil.normalizeIpv4Match(new MatchBuilder().setLayer3Match(new Ipv4MatchBuilder().setIpv4Source(new Ipv4Prefix(source)).setIpv4Destination(new Ipv4Prefix(destination)).build()));
assertEquals("192.168.1.0/24", Ipv4Match.class.cast(matchBuilder.getLayer3Match()).getIpv4Source().getValue());
assertEquals("192.168.2.0/24", Ipv4Match.class.cast(matchBuilder.getLayer3Match()).getIpv4Destination().getValue());
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix in project openflowplugin by opendaylight.
the class MatchNormalizationUtilTest method normalizeArpMatch.
@Test
public void normalizeArpMatch() {
final int arpOp = 10;
final String source = "192.168.1.2/24";
final String destination = "192.168.2.2/24";
final MacAddress sourceHw = new MacAddress("01:23:45:AB:CD:EF");
final MacAddress dstHw = new MacAddress("01:23:45:AB:C0:EF");
final MacAddress mask = new MacAddress("FF:FF:FF:FF:FF:FF");
final MatchBuilder matchBuilder = MatchNormalizationUtil.normalizeArpMatch(new MatchBuilder().setLayer3Match(new ArpMatchBuilder().setArpOp(10).setArpSourceTransportAddress(new Ipv4Prefix(source)).setArpTargetTransportAddress(new Ipv4Prefix(destination)).setArpTargetHardwareAddress(new ArpTargetHardwareAddressBuilder().setAddress(dstHw).setMask(mask).build()).setArpSourceHardwareAddress(new ArpSourceHardwareAddressBuilder().setAddress(sourceHw).setMask(mask).build()).build()));
assertEquals(arpOp, ArpMatch.class.cast(matchBuilder.getLayer3Match()).getArpOp().intValue());
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix in project openflowplugin by opendaylight.
the class MatchNormalizationUtilTest method normalizeTunnelIpv4Match.
@Test
public void normalizeTunnelIpv4Match() {
final String source = "192.168.1.2/24";
final String destination = "192.168.2.2/24";
final MatchBuilder matchBuilder = MatchNormalizationUtil.normalizeTunnelIpv4Match(new MatchBuilder().setLayer3Match(new TunnelIpv4MatchBuilder().setTunnelIpv4Source(new Ipv4Prefix(source)).setTunnelIpv4Destination(new Ipv4Prefix(destination)).build()));
assertEquals("192.168.1.0/24", TunnelIpv4Match.class.cast(matchBuilder.getLayer3Match()).getTunnelIpv4Source().getValue());
assertEquals("192.168.2.0/24", TunnelIpv4Match.class.cast(matchBuilder.getLayer3Match()).getTunnelIpv4Destination().getValue());
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix in project openflowplugin by opendaylight.
the class OfToSalTunnelIpv4SrcCase method process.
@Override
public Optional<MatchBuilder> process(@Nonnull Ipv4SrcCase source, MatchResponseConvertorData data, ConvertorExecutor convertorExecutor) {
final MatchBuilder matchBuilder = data.getMatchBuilder();
final Ipv4MatchBuilder ipv4MatchBuilder = data.getIpv4MatchBuilder();
final TunnelIpv4MatchBuilder tunnelIpv4MatchBuilder = data.getTunnelIpv4MatchBuilder();
Ipv4Src tunnelIpv4Dst = source.getIpv4Src();
if (tunnelIpv4Dst != null) {
String ipv4PrefixStr = tunnelIpv4Dst.getIpv4Address().getValue();
byte[] mask = tunnelIpv4Dst.getMask();
ipv4PrefixStr += IpConversionUtil.PREFIX_SEPARATOR + ByteBuffer.wrap(tunnelIpv4Dst.getMask()).getInt();
final Ipv4Prefix ipv4Prefix;
if (mask != null) {
ipv4Prefix = IpConversionUtil.createPrefix(new Ipv4Address(ipv4PrefixStr), mask);
} else {
// Openflow Spec : 1.3.2
// An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
// So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
// statistics response.
ipv4Prefix = IpConversionUtil.createPrefix(new Ipv4Address(ipv4PrefixStr));
}
ipv4MatchBuilder.setIpv4Source(ipv4Prefix);
matchBuilder.setLayer3Match(tunnelIpv4MatchBuilder.build());
}
return Optional.of(matchBuilder);
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix in project openflowplugin by opendaylight.
the class AbstractMatchEntrySerializer method writeIpv4Prefix.
/**
* Serialize Ipv4 prefix (address and mask).
*
* @param prefix Ipv4 prefix
* @param outBuffer output buffer
*/
protected static void writeIpv4Prefix(final Ipv4Prefix prefix, final ByteBuf outBuffer) {
// Split address to IP and mask
final Iterator<String> addressParts = IpConversionUtil.splitToParts(prefix);
// Write address part of prefix
writeIpv4Address(new Ipv4Address(addressParts.next()), outBuffer);
// If prefix had mask, also write prefix
Optional.ofNullable(MatchConvertorUtil.extractIpv4Mask(addressParts)).ifPresent(mask -> writeMask(mask, outBuffer, EncodeConstants.GROUPS_IN_IPV4_ADDRESS));
}
Aggregations