use of org.onosproject.lisp.msg.protocols.LispMapNotify.NotifyBuilder in project onos by opennetworkinglab.
the class LispMapServer method processMapRegister.
/**
* Handles map-register message and replies with map-notify message.
*
* @param message map-register message
* @return map-notify message
*/
LispMapNotify processMapRegister(LispMessage message) {
LispMapRegister register = (LispMapRegister) message;
if (!checkMapRegisterAuthData(register)) {
log.warn(INVALID_AUTHENTICATION_DATA_MSG, "Map-Register");
return null;
}
register.getMapRecords().forEach(mapRecord -> {
LispEidRecord eidRecord = new LispEidRecord(mapRecord.getMaskLength(), mapRecord.getEidPrefixAfi());
LispMapRecord oldMapRecord = mapDb.getMapRecordByEidRecord(eidRecord, register.isProxyMapReply());
if (oldMapRecord == null) {
mapDb.putMapRecord(eidRecord, mapRecord, register.isProxyMapReply());
} else {
if (oldMapRecord.getMapVersionNumber() <= mapRecord.getMapVersionNumber()) {
mapDb.putMapRecord(eidRecord, mapRecord, register.isProxyMapReply());
if (enableSmr) {
sendSmrMessage(eidRecord);
}
}
}
});
// otherwise, we do not acknowledge back to ETR
if (register.isWantMapNotify()) {
NotifyBuilder notifyBuilder = new DefaultNotifyBuilder();
notifyBuilder.withKeyId(authConfig.lispAuthKeyId());
notifyBuilder.withAuthDataLength(valueOf(authConfig.lispAuthKeyId()).getHashLength());
notifyBuilder.withAuthKey(authConfig.lispAuthKey());
notifyBuilder.withNonce(register.getNonce());
notifyBuilder.withMapRecords(register.getMapRecords());
LispMapNotify notify = notifyBuilder.build();
InetSocketAddress address = new InetSocketAddress(register.getSender().getAddress(), MAP_NOTIFY_PORT);
notify.configSender(address);
return notify;
}
return null;
}
use of org.onosproject.lisp.msg.protocols.LispMapNotify.NotifyBuilder in project onos by opennetworkinglab.
the class LispControllerImplTest method testLispMessagePopulate.
/**
* Tests adding and removing LISP messages.
*/
@Test
public void testLispMessagePopulate() throws InterruptedException {
RegisterBuilder registerBuilder = new DefaultRegisterBuilder();
List<LispMapRecord> records = ImmutableList.of(getMapRecord(), getMapRecord());
LispMapRegister register = registerBuilder.withIsProxyMapReply(true).withIsWantMapNotify(false).withKeyId((short) 1).withAuthKey("onos").withNonce(1L).withMapRecords(records).build();
NotifyBuilder notifyBuilder = new DefaultNotifyBuilder();
LispMapNotify notify = notifyBuilder.withKeyId((short) 1).withAuthKey("onos").withNonce(1L).withMapRecords(records).build();
// Test the callback methods that contained in message listener is fired
agent.processUpstreamMessage(routerId1, register);
// Following line will be ignored
agent.processUpstreamMessage(routerId1, notify);
agent.processDownstreamMessage(routerId1, notify);
// Following line will be ignored
agent.processDownstreamMessage(routerId1, register);
messageListener.waitUntilUpdateIsCalled();
assertThat(messageListener.incomingMessages, hasSize(1));
assertThat(messageListener.incomingMessages, hasItems(register));
assertThat(messageListener.outgoingMessages, hasSize(1));
assertThat(messageListener.outgoingMessages, hasItems(notify));
}
use of org.onosproject.lisp.msg.protocols.LispMapNotify.NotifyBuilder in project onos by opennetworkinglab.
the class DefaultLispMapNotifyTest method setup.
@Before
public void setup() {
NotifyBuilder builder1 = new DefaultNotifyBuilder();
List<LispMapRecord> records1 = ImmutableList.of(getMapRecord(), getMapRecord());
notify1 = builder1.withKeyId((short) 1).withAuthKey(AUTH_KEY).withNonce(1L).withMapRecords(records1).build();
NotifyBuilder builder2 = new DefaultNotifyBuilder();
List<LispMapRecord> records2 = ImmutableList.of(getMapRecord(), getMapRecord());
sameAsNotify1 = builder2.withKeyId((short) 1).withAuthKey(AUTH_KEY).withNonce(1L).withMapRecords(records2).build();
NotifyBuilder builder3 = new DefaultNotifyBuilder();
notify2 = builder3.withKeyId((short) 2).withAuthKey(AUTH_KEY).withNonce(2L).build();
}
use of org.onosproject.lisp.msg.protocols.LispMapNotify.NotifyBuilder in project onos by opennetworkinglab.
the class MappingEntryBuilderTest method testMapNotifyConversion.
@Test
public void testMapNotifyConversion() {
List<LispMapRecord> records = ImmutableList.of(getMapRecord(IP4, UNKNOWN));
NotifyBuilder notifyBuilder = new DefaultNotifyBuilder();
LispMapNotify mapNotify = notifyBuilder.withKeyId(UNIQUE_SHORT).withAuthKey(AUTH_KEY).withNonce(UNIQUE_LONG).withMapRecords(records).build();
List<LispMapRecord> notifyRecords = mapNotify.getMapRecords();
assertThat(notifyRecords.size(), is(1));
testMapRecordConversion(notifyRecords.get(0));
}
Aggregations