use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.SourceEidBuilder in project lispflowmapping by opendaylight.
the class MapRequestSerializer method deserialize.
@SuppressWarnings("checkstyle:IllegalCatch")
public MapRequest deserialize(ByteBuffer requestBuffer, InetAddress sourceRloc) {
try {
final byte typeAndFlags = requestBuffer.get();
final int type = typeAndFlags >> 4;
if (MessageType.forValue(type) != MessageType.MapRequest) {
throw new LispSerializationException("Expected Map-Request packet (type 1), but was type " + type);
}
MapRequestBuilder builder = new MapRequestBuilder();
builder.setAuthoritative(ByteUtil.extractBit(typeAndFlags, Flags.AUTHORITATIVE));
builder.setMapDataPresent(ByteUtil.extractBit(typeAndFlags, Flags.MAP_DATA_PRESENT));
builder.setProbe(ByteUtil.extractBit(typeAndFlags, Flags.PROBE));
builder.setSmr(ByteUtil.extractBit(typeAndFlags, Flags.SMR));
final byte moreFlags = requestBuffer.get();
builder.setPitr(ByteUtil.extractBit(moreFlags, Flags.PITR));
builder.setSmrInvoked(ByteUtil.extractBit(moreFlags, Flags.SMR_INVOKED));
final int itrCount = ByteUtil.getUnsignedByte(requestBuffer) + 1;
final int recordCount = ByteUtil.getUnsignedByte(requestBuffer);
builder.setNonce(requestBuffer.getLong());
LispAddressSerializerContext ctx = new LispAddressSerializerContext(LispAddressSerializerContext.MASK_LEN_MISSING);
builder.setSourceEid(new SourceEidBuilder().setEid(LispAddressSerializer.getInstance().deserializeEid(requestBuffer, ctx)).build());
if (builder.getItrRloc() == null) {
builder.setItrRloc(new ArrayList<ItrRloc>());
}
for (int i = 0; i < itrCount; i++) {
builder.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressSerializer.getInstance().deserializeRloc(requestBuffer)).build());
}
if (builder.getEidItem() == null) {
builder.setEidItem(new ArrayList<EidItem>());
}
for (int i = 0; i < recordCount; i++) {
builder.getEidItem().add(new EidItemBuilder().setEid(EidRecordSerializer.getInstance().deserialize(requestBuffer)).build());
}
if (builder.isMapDataPresent() && requestBuffer.hasRemaining()) {
try {
builder.setMapReply(new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.MapReplyBuilder().setMappingRecord(MappingRecordSerializer.getInstance().deserialize(requestBuffer)).build()).build();
} catch (RuntimeException re) {
LOG.warn("Couldn't deserialize Map-Reply encapsulated in Map-Request", re);
}
}
builder.setSourceRloc(LispAddressUtil.addressBinaryFromInet(sourceRloc));
return builder.build();
} catch (RuntimeException re) {
throw new LispSerializationException("Couldn't deserialize Map-Request (len=" + requestBuffer.capacity() + ")", re);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.SourceEidBuilder in project lispflowmapping by opendaylight.
the class MappingServiceIntegrationTest method queryForAddress.
private MapReply queryForAddress(Eid eid, String srcEid) throws SocketTimeoutException {
MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
mapRequestBuilder.setNonce((long) 4);
mapRequestBuilder.setEidItem(new ArrayList<EidItem>());
mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(eid).build());
mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
if (srcEid != null) {
mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(srcEid)).build());
} else {
mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(ourAddress)).build());
}
mapRequestBuilder.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(ourAddress)).build());
mapRequestBuilder.setAuthoritative(false);
mapRequestBuilder.setMapDataPresent(false);
mapRequestBuilder.setPitr(false);
mapRequestBuilder.setProbe(false);
mapRequestBuilder.setSmr(false);
mapRequestBuilder.setSmrInvoked(false);
sendMapRequest(mapRequestBuilder.build());
return receiveMapReply();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.SourceEidBuilder in project lispflowmapping by opendaylight.
the class MappingServiceIntegrationTestUtil method getDefaultMapRequestBuilder.
/*
* PACKETS CREATION METHODS
*
* In general we return "Builders" so that the caller can customize the fields, but that means it also needs to
* call .build() on the received objects.
*/
/* Map-Request */
/**
* Create a default MapRequestBuilder object.
*
* @param eid the requested EID
* @return the MapRequestBuilder object
*/
static MapRequestBuilder getDefaultMapRequestBuilder(Eid eid) {
MapRequestBuilder mrBuilder = new MapRequestBuilder().setAuthoritative(false).setEidItem(new ArrayList<>()).setItrRloc(new ArrayList<>()).setMapDataPresent(true).setNonce((long) 4).setPitr(false).setProbe(false).setSmr(false).setSmrInvoked(false).setSourceEid(new SourceEidBuilder().setEid(DEFAULT_IPV4_EID).build()).setItrRloc(getDefaultItrRlocList(DEFAULT_IPV4_ITR_RLOC));
mrBuilder.getEidItem().add(new EidItemBuilder().setEid(eid).build());
return mrBuilder;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.SourceEidBuilder in project lispflowmapping by opendaylight.
the class LispMappingServiceTest method handleSmrTest.
/**
* Tests {@link LispMappingService#handleSMR} method.
*/
@Test
public void handleSmrTest() {
final MapRequest mapRequest = Mockito.mock(MapRequest.class);
final Rloc subscriber = LispAddressUtil.asIpv4Rloc(IPV4_STRING_1);
Mockito.when(mapRequest.getSourceEid()).thenReturn(new SourceEidBuilder().setEid(IPV4_SOURCE_EID).build());
Mockito.when(mapRequest.getEidItem()).thenReturn(Lists.newArrayList(EID_ITEM_BUILDER.build()));
// result
final SendMapRequestInputBuilder smrib = new SendMapRequestInputBuilder().setMapRequest(new MapRequestBuilder(mapRequest).build()).setTransportAddress(TRANSPORT_ADDRESS);
lispMappingService.handleSMR(mapRequest, subscriber);
Mockito.verify(odlLispSbService).sendMapRequest(smrib.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.SourceEidBuilder in project lispflowmapping by opendaylight.
the class MapResolverTest method getDefaultMapRequestBuilder.
private static MapRequestBuilder getDefaultMapRequestBuilder() {
MapRequestBuilder mrBuilder = new MapRequestBuilder().setAuthoritative(false).setEidItem(new ArrayList<>()).setItrRloc(new ArrayList<>()).setMapDataPresent(true).setNonce((long) 0).setPitr(false).setProbe(false).setSmr(false).setSmrInvoked(false).setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(IPV4_SOURCE)).build()).setItrRloc(getDefaultItrRlocList());
mrBuilder.getEidItem().add(new EidItemBuilder().setEid(IPV4_PREFIX_EID_1).build());
return mrBuilder;
}
Aggregations