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 ArpSourceTransportAddressEntryDeserializerTest method deserializeEntry.
@Test
public void deserializeEntry() throws Exception {
final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
final Ipv4Prefix arpSourceTransportAddress = new Ipv4Prefix("192.168.0.0/24");
final Ipv4Prefix arpSourceTransportAddressNoMask = new Ipv4Prefix("192.168.0.0/32");
writeHeader(in, false);
Iterator<String> addressParts = IpConversionUtil.splitToParts(arpSourceTransportAddressNoMask);
in.writeBytes(IetfInetUtil.INSTANCE.ipv4AddressBytes(new Ipv4Address(addressParts.next())));
assertEquals(arpSourceTransportAddressNoMask.getValue(), ArpMatch.class.cast(deserialize(in).getLayer3Match()).getArpSourceTransportAddress().getValue());
assertEquals(0, in.readableBytes());
writeHeader(in, true);
addressParts = IpConversionUtil.splitToParts(arpSourceTransportAddress);
in.writeBytes(IetfInetUtil.INSTANCE.ipv4AddressBytes(new Ipv4Address(addressParts.next())));
in.writeBytes(MatchConvertorUtil.extractIpv4Mask(addressParts));
final Ipv4Prefix desAddress = ArpMatch.class.cast(deserialize(in).getLayer3Match()).getArpSourceTransportAddress();
assertEquals(arpSourceTransportAddress.getValue(), desAddress.getValue());
assertEquals(0, in.readableBytes());
}
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 OFPluginFlowTest method createMatch1.
private static MatchBuilder createMatch1() {
MatchBuilder match = new MatchBuilder();
Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24");
ipv4Match.setIpv4Destination(prefix);
Ipv4Match i4m = ipv4Match.build();
match.setLayer3Match(i4m);
EthernetMatchBuilder eth = new EthernetMatchBuilder();
EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
ethTypeBuilder.setType(new EtherType(0x0800L));
eth.setEthernetType(ethTypeBuilder.build());
match.setEthernetMatch(eth.build());
return match;
}
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 MatchConvertorTest method testArpMatchConversionWithMasks.
@Test
public void testArpMatchConversionWithMasks() {
ArpMatchBuilder arpBuilder = new ArpMatchBuilder();
/* Use canonnical prefixes !!! */
arpBuilder.setArpSourceTransportAddress(new Ipv4Prefix("10.0.0.0/8"));
arpBuilder.setArpTargetTransportAddress(new Ipv4Prefix("10.0.0.4/31"));
ArpSourceHardwareAddressBuilder srcHwBuilder = new ArpSourceHardwareAddressBuilder();
srcHwBuilder.setAddress(new MacAddress("00:00:00:00:00:05"));
srcHwBuilder.setMask(new MacAddress("00:00:00:00:00:08"));
arpBuilder.setArpSourceHardwareAddress(srcHwBuilder.build());
ArpTargetHardwareAddressBuilder dstHwBuilder = new ArpTargetHardwareAddressBuilder();
dstHwBuilder.setAddress(new MacAddress("00:00:00:00:00:06"));
dstHwBuilder.setMask(new MacAddress("00:00:00:00:00:09"));
arpBuilder.setArpTargetHardwareAddress(dstHwBuilder.build());
MatchBuilder builder = new MatchBuilder();
builder.setLayer3Match(arpBuilder.build());
Match match = builder.build();
Optional<List<MatchEntry>> entriesOptional = converterManager.convert(match, new VersionConvertorData(OFConstants.OFP_VERSION_1_3));
List<MatchEntry> entries = entriesOptional.get();
Assert.assertEquals("Wrong entries size", 4, entries.size());
MatchEntry entry = entries.get(0);
entry = entries.get(0);
checkEntryHeader(entry, ArpSpa.class, true);
Assert.assertEquals("Wrong arp spa", "10.0.0.0", ((ArpSpaCase) entry.getMatchEntryValue()).getArpSpa().getIpv4Address().getValue());
Assert.assertArrayEquals("Wrong arp spa mask", new byte[] { (byte) 255, 0, 0, 0 }, ((ArpSpaCase) entry.getMatchEntryValue()).getArpSpa().getMask());
entry = entries.get(1);
checkEntryHeader(entry, ArpTpa.class, true);
Assert.assertEquals("Wrong arp tpa", "10.0.0.4", ((ArpTpaCase) entry.getMatchEntryValue()).getArpTpa().getIpv4Address().getValue());
Assert.assertArrayEquals("Wrong arp tpa mask", new byte[] { (byte) 255, (byte) 255, (byte) 255, (byte) 254 }, ((ArpTpaCase) entry.getMatchEntryValue()).getArpTpa().getMask());
entry = entries.get(2);
checkEntryHeader(entry, ArpSha.class, true);
Assert.assertEquals("Wrong arp sha", "00:00:00:00:00:05", ((ArpShaCase) entry.getMatchEntryValue()).getArpSha().getMacAddress().getValue());
Assert.assertArrayEquals("Wrong arp sha mask", new byte[] { 0, 0, 0, 0, 0, 8 }, ((ArpShaCase) entry.getMatchEntryValue()).getArpSha().getMask());
entry = entries.get(3);
checkEntryHeader(entry, ArpTha.class, true);
Assert.assertEquals("Wrong arp tha", "00:00:00:00:00:06", ((ArpThaCase) entry.getMatchEntryValue()).getArpTha().getMacAddress().getValue());
Assert.assertArrayEquals("Wrong arp tha mask", new byte[] { 0, 0, 0, 0, 0, 9 }, ((ArpThaCase) entry.getMatchEntryValue()).getArpTha().getMask());
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix in project bgpcep by opendaylight.
the class GenericConditionPolicyHandler method createPrefixes.
private static List<IpPrefix> createPrefixes(final Prefix prefixContainer) {
final IpPrefix prefix = prefixContainer.getIpPrefix();
if (prefixContainer.getMasklengthRange().equals(EXACT)) {
return Collections.singletonList(prefix);
}
final String[] range = prefixContainer.getMasklengthRange().split("\\..");
boolean ipv4 = false;
final String prefixString;
if (prefix.getIpv4Prefix() != null) {
prefixString = prefix.getIpv4Prefix().getValue();
ipv4 = true;
} else {
prefixString = prefix.getIpv6Prefix().getValue();
}
int from = Integer.parseInt(range[0]);
final List<IpPrefix> prefixes = new ArrayList<>();
while (from <= Integer.parseInt(range[1])) {
final String prefixVal = StringUtils.replacePattern(prefixString, "[/][0-9]+", "/" + Integer.toString(from));
if (ipv4) {
prefixes.add(new IpPrefix(new Ipv4Prefix(prefixVal)));
} else {
prefixes.add(new IpPrefix(new Ipv6Prefix(prefixVal)));
}
from++;
}
return prefixes;
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix in project bgpcep by opendaylight.
the class Ipv4ReachabilityTopologyBuilderTest method setUp.
@Before
@Override
public void setUp() {
super.setUp();
this.ipv4TopoBuilder = new Ipv4ReachabilityTopologyBuilder(getDataBroker(), LOC_RIB_REF, TEST_TOPOLOGY_ID);
this.ipv4TopoBuilder.start();
final InstanceIdentifier<Tables> path = LOC_RIB_REF.getInstanceIdentifier().builder().child(LocRib.class).child(Tables.class, new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class)).build();
this.ipv4RouteIID = path.builder().child((Class) Ipv4Routes.class).child(Ipv4Route.class, new Ipv4RouteKey(new PathId(PATH_ID), new Ipv4Prefix(ROUTE_IP4PREFIX))).build();
}
Aggregations