use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder in project lispflowmapping by opendaylight.
the class LocatorRecordSerializer method deserialize.
protected LocatorRecord deserialize(ByteBuffer buffer) {
LocatorRecordBuilder builder = new LocatorRecordBuilder();
builder.setPriority((short) ByteUtil.getUnsignedByte(buffer));
builder.setWeight((short) ByteUtil.getUnsignedByte(buffer));
builder.setMulticastPriority((short) ByteUtil.getUnsignedByte(buffer));
builder.setMulticastWeight((short) ByteUtil.getUnsignedByte(buffer));
byte flags = (byte) buffer.getShort();
builder.setLocalLocator(ByteUtil.extractBit(flags, Flags.LOCAL_LOCATOR));
builder.setRlocProbed(ByteUtil.extractBit(flags, Flags.RLOC_PROBED));
builder.setRouted(ByteUtil.extractBit(flags, Flags.ROUTED));
Rloc rloc = LispAddressSerializer.getInstance().deserializeRloc(buffer);
builder.setRloc(rloc);
builder.setLocatorId(LispAddressStringifier.getString(rloc));
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder in project lispflowmapping by opendaylight.
the class MappingServiceIntegrationTest method registerAddress.
/*
// This registers an IP with a MapRegister, then adds a password via the
// northbound REST API
// and checks that the password works
public void testPasswordExactMatch() throws Exception {
cleanUP();
String ipString = "10.0.0.1";
LispIpv4Address address = LispAddressUtil.asIPAfiAddress(ipString);
int mask = 32;
String pass = "pass";
URL url = createPutURL("key");
String jsonAuthData = createAuthKeyJSON(pass, address, mask);
LOG.trace("Sending this JSON to LISP server: \n" + jsonAuthData);
LOG.trace("Address: " + address);
byte[] expectedSha = new byte[] { (byte) 146, (byte) 234, (byte) 52, (byte) 247, (byte) 186, (byte) 232,
(byte) 31, (byte) 249, (byte) 87,
(byte) 73, (byte) 234, (byte) 54, (byte) 225, (byte) 160, (byte) 129, (byte) 251, (byte) 73, (byte) 53,
(byte) 196, (byte) 62 };
byte[] zeros = new byte[20];
callURL("PUT", "application/json", "text/plain", jsonAuthData, url);
// build a MapRegister
MapRegisterBuilder mapRegister = new MapRegisterBuilder();
mapRegister.setWantMapNotify(true);
mapRegister.setNonce((long) 8);
EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
etlr.setLispAddressContainer(LispAddressUtil.toContainer(address));
etlr.setMaskLength((short) mask);
etlr.setRecordTtl(254);
LocatorRecordBuilder record = new LocatorRecordBuilder();
record.setLispAddressContainer(LispAddressUtil.toContainer(locatorEid));
etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
etlr.getLocatorRecord().add(record.build());
mapRegister.setMappingRecordItem(new ArrayList<MappingRecordItem>());
mapRegister.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlr.build()).build());
mapRegister.setKeyId((short) 1); // LispKeyIDEnum.SHA1.getKeyID()
mapRegister.setAuthenticationData(zeros);
sendMapRegister(mapRegister.build());
assertNoPacketReceived(3000);
mapRegister.setAuthenticationData(expectedSha);
sendMapRegister(mapRegister.build());
assertMapNotifyReceived();
}
public void testPasswordMaskMatch() throws Exception {
cleanUP();
LispIpv4Address addressInRange = LispAddressUtil.asIPAfiAddress("10.20.30.40");
LispIpv4Address addressOutOfRange = LispAddressUtil.asIPAfiAddress("20.40.30.40");
LispIpv4Address range = LispAddressUtil.asIPAfiAddress("10.20.30.0");
int mask = 32;
String pass = "pass";
URL url = createPutURL("key");
String jsonAuthData = createAuthKeyJSON(pass, range, 8);
callURL("PUT", "application/json", "text/plain", jsonAuthData, url);
// build a MapRegister
MapRegisterBuilder mapRegister = new MapRegisterBuilder();
mapRegister.setWantMapNotify(true);
mapRegister.setNonce((long) 8);
EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
etlr.setLispAddressContainer(LispAddressUtil.toContainer(addressInRange));
etlr.setMaskLength((short) mask);
etlr.setRecordTtl(254);
LocatorRecordBuilder record = new LocatorRecordBuilder();
record.setLispAddressContainer(LispAddressUtil.toContainer(locatorEid));
record.setLispAddressContainer(LispAddressUtil.toContainer(locatorEid));
etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
etlr.getLocatorRecord().add(record.build());
mapRegister.setMappingRecordItem(new ArrayList<MappingRecordItem>());
mapRegister.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlr.build()).build());
mapRegister.setKeyId((short) 1); // LispKeyIDEnum.SHA1.getKeyID()
mapRegister
.setAuthenticationData(new byte[] { -15, -52, 38, -94, 125, -111, -68, -79, 68, 6, 101, 45, -1, 47, -4,
-67, -113, 104, -110, -71 });
sendMapRegister(mapRegister.build());
assertMapNotifyReceived();
etlr.setLispAddressContainer(LispAddressUtil.toContainer(addressOutOfRange));
mapRegister
.setAuthenticationData(new byte[] { -54, 68, -58, -91, -23, 22, -88, -31, 113, 39, 115, 78, -68, -123,
-71, -14, -99, 67, -23, -73 });
sendMapRegister(mapRegister.build());
assertNoPacketReceived(3000);
}
*/
// takes an address, packs it in a MapRegister and sends it
private void registerAddress(Eid eid) throws SocketTimeoutException {
mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
sleepForSeconds(1);
MapRegister mapRegister = MappingServiceIntegrationTestUtil.getDefaultMapRegisterBuilder(eid).build();
sendMapRegister(mapRegister);
MapNotify mapNotify = receiveMapNotify();
assertEquals(8, mapNotify.getNonce().longValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder in project lispflowmapping by opendaylight.
the class MappingServiceIntegrationTestUtil method getDefaultLocatorBuilder.
/**
* Create a default LocatorRecordBuilder object.
*
* @param rloc RLOC for the mapping record, if null, a default will be added
* @return the LocatorRecordBuilder object
*/
static LocatorRecordBuilder getDefaultLocatorBuilder(Rloc rloc) {
if (rloc == null) {
rloc = DEFAULT_IPV4_RLOC;
LOG.warn("getDefaultLocatorBuilder(): null RLOC received, using the default {}", DEFAULT_IPV4_RLOC_STRING);
}
return new LocatorRecordBuilder().setLocalLocator(true).setMulticastPriority((short) 255).setMulticastWeight((short) 0).setPriority((short) 1).setRlocProbed(false).setRouted(true).setWeight((short) 1).setKey(new LocatorRecordKey(LispAddressStringifier.getString(rloc))).setRloc(rloc);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder in project lispflowmapping by opendaylight.
the class MultiSiteScenario method provideLocatorRecord.
private LocatorRecord provideLocatorRecord(final Rloc rloc, final String rlocStr, final short weight, final short priority) {
final LocatorRecordBuilder locatorRecordBuilder = new LocatorRecordBuilder();
locatorRecordBuilder.setRloc(rloc);
locatorRecordBuilder.setLocatorId(rlocStr);
locatorRecordBuilder.setPriority(priority);
locatorRecordBuilder.setWeight(weight);
locatorRecordBuilder.setMulticastPriority(DEFAULT_MULTICAST_PRIORITY);
locatorRecordBuilder.setMulticastWeight(DEFAULT_MULTICAST_WEIGHT);
locatorRecordBuilder.setLocalLocator(DEFAULT_LOCAL_LOCATOR);
locatorRecordBuilder.setRlocProbed(DEFAULT_RLOC_PROBED);
locatorRecordBuilder.setRouted(DEFAULT_ROUTED);
return locatorRecordBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder in project lispflowmapping by opendaylight.
the class MappingMergeUtil method getCommonLocatorRecords.
private static List<LocatorRecord> getCommonLocatorRecords(MappingRecord nbMapping, MappingRecord sbMapping) {
// Return null when NB is a negative mapping
if (nbMapping.getLocatorRecord() == null || nbMapping.getLocatorRecord().isEmpty()) {
return null;
}
List<LocatorRecord> sbLocators = sbMapping.getLocatorRecord();
// We assume locators are unique and don't show up several times (with different or identical p/w/mp/mw),
// so we create a HashMap of the locators from the SB mapping record, keyed by the Rloc
Map<Rloc, LocatorRecord> sbLocatorMap = new HashMap<Rloc, LocatorRecord>();
for (LocatorRecord locator : sbLocators) {
sbLocatorMap.put(locator.getRloc(), locator);
}
// Gradually building final list of common locators, in order that they appear in NB Mapping
List<LocatorRecord> commonLocators = new ArrayList<LocatorRecord>();
for (LocatorRecord nbLocator : nbMapping.getLocatorRecord()) {
Rloc nbRloc = nbLocator.getRloc();
if (sbLocatorMap.containsKey(nbRloc)) {
if (sbLocatorMap.get(nbRloc).getPriority() == (short) 255) {
// if SB locator has p == 255 then common locator takes all NB fields except for p
// which must be set to 255
LocatorRecordBuilder lrb = new LocatorRecordBuilder(nbLocator);
lrb.setPriority((short) 255);
commonLocators.add(lrb.build());
} else {
commonLocators.add(nbLocator);
}
}
}
return commonLocators;
}
Aggregations