use of org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address in project lispflowmapping by opendaylight.
the class LispAddressUtilTest method asEid.
/**
* Tests {@link LispAddressUtil#asEid(SimpleAddress, InstanceIdType)} method.
*/
@Test
public void asEid() {
final Eid eid = LispAddressUtil.asEid(SIMPLE_ADDRESS_IPV4_TEST, INSTANCE_ID_TYPE_TEST);
assertNotNull(eid);
assertEquals(Ipv4BinaryAfi.class, eid.getAddressType());
final Ipv4Binary address = (Ipv4Binary) eid.getAddress();
assertArrayEquals(InetAddresses.forString(SIMPLE_ADDRESS_IPV4_TEST.getIpAddress().getIpv4Address().getValue()).getAddress(), address.getIpv4Binary().getValue());
assertEquals(INSTANCE_ID_TYPE_TEST, eid.getVirtualNetworkId());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address in project lispflowmapping by opendaylight.
the class LispAddressUtilTest method addressFromIpPrefix_ipv4.
/**
* Tests {@link LispAddressUtil#addressFromIpPrefix(IpPrefix)} and {@link
* LispAddressUtil#addressTypeFromIpPrefix(IpPrefix)}
* methods with ipv4 address.
*/
@Test
public void addressFromIpPrefix_ipv4() {
IpPrefix ipv4Prefix = new IpPrefix(new Ipv4Prefix(IPV4_ADDRESS_PREFIX_VALUE_TEST));
final Class<? extends LispAddressFamily> addressClass = LispAddressUtil.addressTypeFromIpPrefix(ipv4Prefix);
assertEquals(Ipv4PrefixAfi.class, addressClass);
final Address address = LispAddressUtil.addressFromIpPrefix(ipv4Prefix);
assertTrue(address instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix);
assertEquals(IPV4_ADDRESS_PREFIX_VALUE_TEST, ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix) address).getIpv4Prefix().getValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address in project lispflowmapping by opendaylight.
the class LispAddressUtilTest method addressFromServicePathTest_withServicePath.
/**
* Test {@link LispAddressUtil#addressFromServicePath(ServicePath)} method with concrete servicePath.
*/
@Test
public void addressFromServicePathTest_withServicePath() {
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.service.path.ServicePathBuilder servicePathBuilder = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.service.path.ServicePathBuilder();
servicePathBuilder.setServiceIndex(SERVICE_INDEX_TEST);
servicePathBuilder.setServicePathId(new ServicePathIdType(DUMMY_SERVICE_PATH_ID_TYPE));
ServicePath expectedAddress = servicePathBuilder.build();
final Address testedAddress = LispAddressUtil.addressFromServicePath(expectedAddress);
assertTrue(testedAddress instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ServicePath);
assertEquals(expectedAddress, ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ServicePath) testedAddress).getServicePath());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address in project lispflowmapping by opendaylight.
the class MapRequestSerializer method serialize.
public ByteBuffer serialize(MapRequest mapRequest) {
int size = Length.HEADER_SIZE;
if (mapRequest.getSourceEid() != null && mapRequest.getSourceEid().getEid() != null) {
size += LispAddressSerializer.getInstance().getAddressSize(mapRequest.getSourceEid().getEid());
} else {
size += 2;
}
if (mapRequest.getItrRloc() != null) {
for (ItrRloc address : mapRequest.getItrRloc()) {
size += LispAddressSerializer.getInstance().getAddressSize(address.getRloc());
}
}
if (mapRequest.getEidItem() != null) {
for (EidItem record : mapRequest.getEidItem()) {
size += 2 + LispAddressSerializer.getInstance().getAddressSize(record.getEid());
}
}
ByteBuffer requestBuffer = ByteBuffer.allocate(size);
requestBuffer.put((byte) ((byte) (MessageType.MapRequest.getIntValue() << 4) | ByteUtil.boolToBit(BooleanUtils.isTrue(mapRequest.isAuthoritative()), Flags.AUTHORITATIVE) | ByteUtil.boolToBit(BooleanUtils.isTrue(mapRequest.isMapDataPresent()), Flags.MAP_DATA_PRESENT) | ByteUtil.boolToBit(BooleanUtils.isTrue(mapRequest.isProbe()), Flags.PROBE) | ByteUtil.boolToBit(BooleanUtils.isTrue(mapRequest.isSmr()), Flags.SMR)));
requestBuffer.put((byte) (ByteUtil.boolToBit(BooleanUtils.isTrue(mapRequest.isPitr()), Flags.PITR) | ByteUtil.boolToBit(BooleanUtils.isTrue(mapRequest.isSmrInvoked()), Flags.SMR_INVOKED)));
if (mapRequest.getItrRloc() != null) {
int irc = mapRequest.getItrRloc().size();
if (irc > 0) {
irc--;
}
requestBuffer.put((byte) (irc));
} else {
requestBuffer.put((byte) 0);
}
if (mapRequest.getEidItem() != null) {
requestBuffer.put((byte) mapRequest.getEidItem().size());
} else {
requestBuffer.put((byte) 0);
}
requestBuffer.putLong(NumberUtil.asLong(mapRequest.getNonce()));
if (mapRequest.getSourceEid() != null && mapRequest.getSourceEid().getEid() != null) {
LispAddressSerializer.getInstance().serialize(requestBuffer, mapRequest.getSourceEid().getEid());
} else {
requestBuffer.putShort((short) 0);
}
if (mapRequest.getItrRloc() != null) {
for (ItrRloc address : mapRequest.getItrRloc()) {
LispAddressSerializer.getInstance().serialize(requestBuffer, address.getRloc());
}
}
if (mapRequest.getEidItem() != null) {
for (EidItem record : mapRequest.getEidItem()) {
requestBuffer.put((byte) 0);
requestBuffer.put((byte) MaskUtil.getMaskForAddress(record.getEid().getAddress()));
LispAddressSerializer.getInstance().serialize(requestBuffer, record.getEid());
}
}
if (mapRequest.getMapReply() != null) {
ByteBuffer replyBuffer = ByteBuffer.allocate(MappingRecordSerializer.getInstance().getSerializationSize(mapRequest.getMapReply().getMappingRecord()));
MappingRecordSerializer.getInstance().serialize(replyBuffer, mapRequest.getMapReply().getMappingRecord());
ByteBuffer combinedBuffer = ByteBuffer.allocate(requestBuffer.capacity() + replyBuffer.capacity());
combinedBuffer.put(requestBuffer.array());
combinedBuffer.put(replyBuffer.array());
return combinedBuffer;
}
return requestBuffer;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address in project lispflowmapping by opendaylight.
the class AfiListSerializer method getLcafLength.
@Override
protected short getLcafLength(LispAddress lispAddress) {
short totalSize = 0;
AfiList afiList = (((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.AfiList) lispAddress.getAddress()).getAfiList());
for (SimpleAddress address : afiList.getAddressList()) {
totalSize += SimpleAddressSerializer.getInstance().getAddressSize(address);
}
return totalSize;
}
Aggregations