import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey;
+import org.opendaylight.yangtools.yang.binding.Notification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public static final ServiceGroupIdentifier SERVICE_GROUP_IDENTIFIER = ServiceGroupIdentifier.create(
LISPFLOWMAPPING_ENTITY_NAME);
+ private volatile boolean isMaster = false;
private volatile String bindingAddress;
private AuthKeyDb akdb;
private MapRegisterCache mapRegisterCache = new MapRegisterCache();
restoreDaoFromDatastore();
LispSouthboundHandler lispSouthboundHandler = new LispSouthboundHandler(this);
- lispSouthboundHandler.setDataBroker(dataBroker);
- lispSouthboundHandler.setNotificationProvider(notificationPublishService);
- lispSouthboundHandler.setAuthKeyDb(akdb);
- lispSouthboundHandler.setMapRegisterCache(mapRegisterCache);
- lispSouthboundHandler.setMapRegisterCacheTimeout(mapRegisterCacheTimeout);
- lispSouthboundHandler.setAuthenticationKeyDataListener(authenticationKeyDataListener);
- lispSouthboundHandler.setStats(statistics);
this.lispSouthboundHandler = lispSouthboundHandler;
- LispXtrSouthboundHandler lispXtrSouthboundHandler = new LispXtrSouthboundHandler();
- lispXtrSouthboundHandler.setNotificationProvider(notificationPublishService);
+ LispXtrSouthboundHandler lispXtrSouthboundHandler = new LispXtrSouthboundHandler(this);
this.lispXtrSouthboundHandler = lispXtrSouthboundHandler;
if (Epoll.isAvailable()) {
return null;
}
- public ConcurrentLispSouthboundStats getStats() {
- return statistics;
- }
-
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public void setLispAddress(String address) {
@Override
public void instantiateServiceInstance() {
- if (lispSouthboundHandler != null) {
- lispSouthboundHandler.setNotificationProvider(notificationPublishService);
- lispSouthboundHandler.setIsMaster(true);
- }
- if (lispXtrSouthboundHandler != null) {
- lispXtrSouthboundHandler.setNotificationProvider(notificationPublishService);
- }
+ this.isMaster = true;
}
@Override
public ListenableFuture<Void> closeServiceInstance() {
- if (lispSouthboundHandler != null) {
- lispSouthboundHandler.setNotificationProvider(null);
- lispSouthboundHandler.setIsMaster(false);
- }
- if (lispXtrSouthboundHandler != null) {
- lispXtrSouthboundHandler.setNotificationProvider(null);
- }
+ this.isMaster = false;
return Futures.<Void>immediateFuture(null);
}
return SERVICE_GROUP_IDENTIFIER;
}
+ public synchronized void sendNotificationIfPossible(final Notification notification) throws InterruptedException {
+ if (isMaster && notificationPublishService != null) {
+ notificationPublishService.putNotification(notification);
+ LOG.trace("Publishing notification: {}", notification);
+ } else if (notificationPublishService == null) {
+ LOG.warn("Can't publish notification because no reference to publication service exists!");
+ }
+ }
+
+ public AuthKeyDb getAkdb() {
+ return akdb;
+ }
+
+ public ConcurrentLispSouthboundStats getStats() {
+ return statistics;
+ }
+
+ public DataBroker getDataBroker() {
+ return dataBroker;
+ }
+
+ public AuthenticationKeyDataListener getAuthenticationKeyDataListener() {
+ return authenticationKeyDataListener;
+ }
+
public MapRegisterCache getMapRegisterCache() {
return mapRegisterCache;
}
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
import org.opendaylight.lispflowmapping.config.ConfigIni;
import org.opendaylight.lispflowmapping.lisp.authentication.ILispAuthentication;
import org.opendaylight.lispflowmapping.lisp.authentication.LispAuthenticationUtil;
import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier;
import org.opendaylight.lispflowmapping.lisp.util.MapRequestUtil;
-import org.opendaylight.lispflowmapping.mapcache.AuthKeyDb;
import org.opendaylight.lispflowmapping.southbound.ConcurrentLispSouthboundStats;
import org.opendaylight.lispflowmapping.southbound.LispSouthboundPlugin;
-import org.opendaylight.lispflowmapping.southbound.lisp.cache.MapRegisterCache;
import org.opendaylight.lispflowmapping.southbound.lisp.cache.MapRegisterPartialDeserializer;
import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
import org.opendaylight.lispflowmapping.southbound.lisp.network.PacketHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddressBuilder;
-import org.opendaylight.yangtools.yang.binding.Notification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ChannelHandler.Sharable
public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramPacket>
implements ILispSouthboundService, AutoCloseable {
- private MapRegisterCache mapRegisterCache;
- private long mapRegisterCacheTimeout;
-
- private DataBroker dataBroker;
- private NotificationPublishService notificationPublishService;
-
protected static final Logger LOG = LoggerFactory.getLogger(LispSouthboundHandler.class);
//TODO: think whether this field can be accessed through mappingservice or some other configuration parameter
private boolean authenticationEnabled = ConfigIni.getInstance().isAuthEnabled();
private final LispSouthboundPlugin lispSbPlugin;
- private ConcurrentLispSouthboundStats lispSbStats = null;
- private AuthKeyDb akdb;
- private AuthenticationKeyDataListener authenticationKeyDataListener;
private boolean isReadFromChannelEnabled = true;
private Channel channel;
LispNotificationHelper.getIpAddressBinaryFromInetAddress(finalSourceAddress));
transportAddressBuilder.setPort(new PortNumber(port));
requestMappingBuilder.setTransportAddress(transportAddressBuilder.build());
- if (notificationPublishService != null) {
- notificationPublishService.putNotification(requestMappingBuilder.build());
- LOG.trace("MapRequest was published!");
- } else {
- LOG.warn("Notification Provider is null!");
- }
+ lispSbPlugin.sendNotificationIfPossible(requestMappingBuilder.build());
} catch (RuntimeException re) {
throw new LispMalformedPacketException("Couldn't deserialize Map-Request (len="
+ inBuffer.capacity() + ")", re);
cacheValue = resolveCacheValue(artificialEntry);
}
if (cacheValue != null) {
- lispSbStats.incrementCacheHits();
+ lispSbPlugin.getStats().incrementCacheHits();
MapRegisterCacheMetadata mapRegisterMeta = cacheValue.getMapRegisterCacheMetadata();
LOG.debug("Map register message site-ID: {} xTR-ID: {} from cache.", mapRegisterMeta.getSiteId(),
mapRegisterMeta.getXtrId());
cacheValue = refreshEntry(cacheKey);
if (cacheValue != null) {
- sendNotificationIfPossible(createMappingKeepAlive(cacheValue));
+ lispSbPlugin.sendNotificationIfPossible(createMappingKeepAlive(cacheValue));
if (cacheValue.getMapRegisterCacheMetadata().isWantMapNotify()) {
sendMapNotifyMsg(inBuffer, sourceAddress, port, cacheValue);
}
}
} else {
- lispSbStats.incrementCacheMisses();
+ lispSbPlugin.getStats().incrementCacheMisses();
MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(inBuffer, sourceAddress);
MappingAuthkey mappingAuthkey = null;
sourceAddress));
transportAddressBuilder.setPort(new PortNumber(port));
addMappingBuilder.setTransportAddress(transportAddressBuilder.build());
- sendNotificationIfPossible(addMappingBuilder.build());
+ lispSbPlugin.sendNotificationIfPossible(addMappingBuilder.build());
if (artificialEntry != null) {
final MapRegisterCacheMetadataBuilder cacheMetadataBldNew = new
MapRegisterCacheMetadataBuilder();
cacheValueBldNew.setMappingAuthkey(mappingAuthkey);
cacheValueBldNew.setMapRegisterCacheMetadata(cacheMetadataBldNew.build());
- mapRegisterCache.addEntry(cacheKey, cacheValueBldNew.build());
+ lispSbPlugin.getMapRegisterCache().addEntry(cacheKey, cacheValueBldNew.build());
}
}
} catch (RuntimeException re) {
}
private MapRegisterCacheValue refreshEntry(final MapRegisterCacheKey cacheKey) {
- MapRegisterCacheValue mapRegisterCacheValue = mapRegisterCache.refreshEntry(cacheKey);
+ MapRegisterCacheValue mapRegisterCacheValue = lispSbPlugin.getMapRegisterCache().refreshEntry(cacheKey);
if (mapRegisterCacheValue != null) {
mapRegisterCacheValue = refreshAuthKeyIfNecessary(mapRegisterCacheValue);
- mapRegisterCache.addEntry(cacheKey, mapRegisterCacheValue);
+ lispSbPlugin.getMapRegisterCache().addEntry(cacheKey, mapRegisterCacheValue);
return mapRegisterCacheValue;
}
return null;
private MapRegisterCacheValue refreshAuthKeyIfNecessary(MapRegisterCacheValue mapRegisterCacheValue) {
final List<EidLispAddress> eids = mapRegisterCacheValue.getMapRegisterCacheMetadata().getEidLispAddress();
- if (authenticationKeyDataListener.authKeysForEidsUnchanged(eids, mapRegisterCacheTimeout)) {
+ if (lispSbPlugin.getAuthenticationKeyDataListener().authKeysForEidsUnchanged(
+ eids, lispSbPlugin.getMapRegisterCacheTimeout())) {
return mapRegisterCacheValue;
}
private MapRegisterCacheValue resolveCacheValue(Map.Entry<MapRegisterCacheKey, byte[]> entry) {
if (entry != null) {
- final MapRegisterCacheValue mapRegisterCacheValue = mapRegisterCache.getEntry(entry.getKey());
+ final MapRegisterCacheValue mapRegisterCacheValue =
+ lispSbPlugin.getMapRegisterCache().getEntry(entry.getKey());
if (mapRegisterCacheValue != null) {
final long creationTime = mapRegisterCacheValue.getMapRegisterCacheMetadata().getTimestamp();
final long currentTime = System.currentTimeMillis();
- if (currentTime - creationTime > mapRegisterCacheTimeout) {
- mapRegisterCache.removeEntry(entry.getKey());
+ if (currentTime - creationTime > lispSbPlugin.getMapRegisterCacheTimeout()) {
+ lispSbPlugin.getMapRegisterCache().removeEntry(entry.getKey());
return null;
} else if (Arrays.equals(mapRegisterCacheValue.getPacketData(), entry.getValue())) {
return mapRegisterCacheValue;
return null;
}
- private void sendNotificationIfPossible(final Notification notification) throws InterruptedException {
- if (notificationPublishService != null) {
- notificationPublishService.putNotification(notification);
- LOG.trace("{} was published.", notification.getClass());
- } else {
- LOG.warn("Notification Provider is null!");
- }
- }
-
private MappingKeepAlive createMappingKeepAlive(final MapRegisterCacheValue value) {
MappingKeepAliveBuilder mappingKeepAliveBuilder = new MappingKeepAliveBuilder();
mappingKeepAliveBuilder.setMapRegisterCacheMetadata(value.getMapRegisterCacheMetadata());
for (int i = 0; i < eidLispAddresses.size(); i++) {
final Eid eid = eidLispAddresses.get(i).getEid();
if (i == 0) {
- firstAuthKey = akdb.getAuthenticationKey(eid);
+ firstAuthKey = lispSbPlugin.getAkdb().getAuthenticationKey(eid);
} else {
- final MappingAuthkey authKey = akdb.getAuthenticationKey(eid);
+ final MappingAuthkey authKey = lispSbPlugin.getAkdb().getAuthenticationKey(eid);
if (!Objects.equals(firstAuthKey, authKey)) {
return null;
}
*
* <p>Methods pass through all records from map register message. For the EID of the first record it gets
* authentication key and does validation of authentication data again this authentication key. If it pass
- * it just checks for remaining records (and its EID) whether they have the same authenticatin key stored in
- * the authentication key database (akdb).
+ * it just checks for remaining records (and its EID) whether they have the same authentication key stored in
+ * the authentication key database.
*
* @return Returns authentication key if all of EIDs have the same authentication key or null otherwise
*/
private MappingAuthkey tryToAuthenticateMessage(final MapRegister mapRegister, final ByteBuffer byteBuffer) {
- if (akdb == null) {
+ if (lispSbPlugin.getAkdb() == null) {
LOG.debug("Simple map cache wasn't instantieted and set.");
return null;
}
final MappingRecordItem recordItem = mappingRecords.get(i);
final MappingRecord mappingRecord = recordItem.getMappingRecord();
if (i == 0) {
- firstAuthKey = akdb.getAuthenticationKey(mappingRecord.getEid());
+ firstAuthKey = lispSbPlugin.getAkdb().getAuthenticationKey(mappingRecord.getEid());
if (!LispAuthenticationUtil.validate(mapRegister, byteBuffer, mappingRecord.getEid(), firstAuthKey)) {
return null;
}
} else {
final Eid eid = mappingRecord.getEid();
- final MappingAuthkey authKey = akdb.getAuthenticationKey(eid);
+ final MappingAuthkey authKey = lispSbPlugin.getAkdb().getAuthenticationKey(eid);
if (!firstAuthKey.equals(authKey)) {
LOG.debug("Map register packet contained several eids. Authentication keys for first one and for "
+ "{} are different.",LispAddressStringifier.getString(eid));
.getIpAddressBinaryFromInetAddress(sourceAddress));
transportAddressBuilder.setPort(new PortNumber(port));
gotMapNotifyBuilder.setTransportAddress(transportAddressBuilder.build());
- if (notificationPublishService != null) {
- notificationPublishService.putNotification(gotMapNotifyBuilder.build());
- LOG.trace("MapNotify was published!");
- } else {
- LOG.warn("Notification Provider is null!");
- }
+ lispSbPlugin.sendNotificationIfPossible(gotMapNotifyBuilder.build());
} catch (RuntimeException re) {
throw new LispMalformedPacketException("Couldn't deserialize Map-Notify (len="
+ inBuffer.capacity() + ")", re);
.getIpAddressBinaryFromInetAddress(sourceAddress));
transportAddressBuilder.setPort(new PortNumber(port));
gotMapReplyBuilder.setTransportAddress(transportAddressBuilder.build());
- if (notificationPublishService != null) {
- notificationPublishService.putNotification(gotMapReplyBuilder.build());
- LOG.trace("MapReply was published!");
- } else {
- LOG.warn("Notification Provider is null!");
- }
+ lispSbPlugin.sendNotificationIfPossible(gotMapReplyBuilder.build());
} catch (RuntimeException re) {
throw new LispMalformedPacketException("Couldn't deserialize Map-Reply (len="
+ inBuffer.capacity() + ")", re);
}
private void handleStats(int type) {
- if (lispSbStats != null) {
+ if (lispSbPlugin.getStats() != null) {
if (type <= ConcurrentLispSouthboundStats.MAX_LISP_TYPES) {
- lispSbStats.incrementRx(type);
+ lispSbPlugin.getStats().incrementRx(type);
} else {
- lispSbStats.incrementRxUnknown();
+ lispSbPlugin.getStats().incrementRxUnknown();
}
}
}
@Override
public void close() throws Exception {
}
-
- public void setAuthKeyDb(final AuthKeyDb smc) {
- this.akdb = smc;
- }
-
- public void setDataBroker(final DataBroker dataBroker) {
- this.dataBroker = dataBroker;
- }
-
- public void setNotificationProvider(NotificationPublishService nps) {
- this.notificationPublishService = nps;
- }
-
- public void setMapRegisterCache(final MapRegisterCache mapRegisterCache) {
- this.mapRegisterCache = mapRegisterCache;
- }
-
- public void setAuthenticationKeyDataListener(AuthenticationKeyDataListener authenticationKeyDataListener) {
- this.authenticationKeyDataListener = authenticationKeyDataListener;
- }
-
- public void setStats(ConcurrentLispSouthboundStats lispSbStats) {
- this.lispSbStats = lispSbStats;
- }
-
- public void setIsMaster(boolean isReadFromChannelEnabled) {
- this.isReadFromChannelEnabled = isReadFromChannelEnabled;
- }
-
- public void setMapRegisterCacheTimeout(long mapRegisterCacheTimeout) {
- this.mapRegisterCacheTimeout = mapRegisterCacheTimeout;
- }
}
import io.netty.channel.socket.DatagramPacket;
import java.net.InetAddress;
import java.nio.ByteBuffer;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
import org.opendaylight.lispflowmapping.lisp.serializer.MapReplySerializer;
import org.opendaylight.lispflowmapping.lisp.serializer.MapRequestSerializer;
import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
import org.opendaylight.lispflowmapping.lisp.util.MapRequestUtil;
+import org.opendaylight.lispflowmapping.southbound.LispSouthboundPlugin;
import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
import org.opendaylight.lispflowmapping.southbound.util.LispNotificationHelper;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
public class LispXtrSouthboundHandler extends SimpleChannelInboundHandler<DatagramPacket>
implements ILispSouthboundService {
- private NotificationPublishService notificationPublishService;
+ private final LispSouthboundPlugin lispSbPlugin;
protected static final Logger LOG = LoggerFactory.getLogger(LispXtrSouthboundHandler.class);
- public void setNotificationProvider(NotificationPublishService nps) {
- this.notificationPublishService = nps;
+ public LispXtrSouthboundHandler(LispSouthboundPlugin lispSbPlugin) {
+ this.lispSbPlugin = lispSbPlugin;
}
public void handlePacket(DatagramPacket packet) {
LispNotificationHelper.getIpAddressBinaryFromInetAddress(finalSourceAddress));
transportAddressBuilder.setPort(new PortNumber(LispMessage.PORT_NUM));
requestMappingBuilder.setTransportAddress(transportAddressBuilder.build());
- if (notificationPublishService != null) {
- notificationPublishService.putNotification(requestMappingBuilder.build());
- LOG.trace("MapRequest was published!");
- } else {
- LOG.warn("Notification Provider is null!");
- }
+ lispSbPlugin.sendNotificationIfPossible(requestMappingBuilder.build());
} catch (RuntimeException re) {
throw new LispMalformedPacketException(
"Couldn't deserialize Map-Request (len=" + inBuffer.capacity() + ")", re);
XtrReplyMappingBuilder replyMappingBuilder = new XtrReplyMappingBuilder();
replyMappingBuilder.setMapReply(LispNotificationHelper.convertMapReply(reply));
-
- if (notificationPublishService != null) {
- notificationPublishService.putNotification(replyMappingBuilder.build());
- LOG.trace("MapReply was published!");
- } else {
- LOG.warn("Notification Provider is null!");
- }
+ lispSbPlugin.sendNotificationIfPossible(replyMappingBuilder.build());
} catch (RuntimeException re) {
throw new LispMalformedPacketException(
"Couldn't deserialize Map-Reply (len=" + buffer.capacity() + ")", re);
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
import static org.opendaylight.lispflowmapping.southbound.lisp.MapRegisterCacheTestUtil.DATA1;
import static org.opendaylight.lispflowmapping.southbound.lisp.MapRegisterCacheTestUtil.DATA2;
import static org.opendaylight.lispflowmapping.southbound.lisp.MapRegisterCacheTestUtil.DATA3;
import java.util.List;
import junitx.framework.ArrayAssert;
import org.apache.commons.lang3.ArrayUtils;
-import org.jmock.api.Invocation;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.AdditionalMatchers;
+import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.Matchers;
import org.mockito.Mockito;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
import org.opendaylight.lispflowmapping.lisp.serializer.MapNotifySerializer;
import org.opendaylight.lispflowmapping.lisp.serializer.MapReplySerializer;
import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
-import org.opendaylight.lispflowmapping.lisp.util.MapNotifyBuilderHelper;
import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
import org.opendaylight.lispflowmapping.mapcache.AuthKeyDb;
import org.opendaylight.lispflowmapping.southbound.ConcurrentLispSouthboundStats;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv4PrefixBinaryAfi;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv6PrefixBinaryAfi;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.AddMapping;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MessageType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.RequestMapping;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
public class LispSouthboundServiceTest extends BaseTestCase {
private LispSouthboundHandler testedLispService;
- private NotificationPublishService nps;
private byte[] mapRequestPacket;
private byte[] mapRegisterPacket;
- private ValueSaverAction<Notification> lispNotificationSaver;
- // private ValueSaverAction<MapRegister> mapRegisterSaver;
- // private ValueSaverAction<MapRequest> mapRequestSaver;
private MapNotifyBuilder mapNotifyBuilder;
private MapReplyBuilder mapReplyBuilder;
private MappingRecordBuilder mappingRecordBuilder;
private MapRegisterCache mapRegisterCache;
private LispSouthboundPlugin mockLispSouthboundPlugin;
- private ConcurrentLispSouthboundStats lispSouthboundStats;
+ private LispSouthboundPlugin contextMockLispSouthboundPlugin;
private static final long CACHE_RECORD_TIMEOUT = 90000;
private static AuthKeyDb akdb;
int LOCATOR = MapReplyIpv4SingleLocatorPos.LOCATOR + FIRST_LOCATOR_IPV4_LENGTH;
}
+ @SuppressWarnings("unchecked")
@BeforeClass
public static void initTests() {
akdb = Mockito.mock(AuthKeyDb.class);
@Before
public void before() throws Exception {
super.before();
- // mapResolver = context.mock(IMapResolver.class);
- // mapServer = context.mock(IMapServer.class);
- mockLispSouthboundPlugin = mock(LispSouthboundPlugin.class);
+ mockLispSouthboundPlugin = Mockito.mock(LispSouthboundPlugin.class);
+ contextMockLispSouthboundPlugin = context.mock(LispSouthboundPlugin.class);
Mockito.when(mockLispSouthboundPlugin.isMapRegisterCacheEnabled()).thenReturn(true);
- testedLispService = new LispSouthboundHandler(mockLispSouthboundPlugin);
- testedLispService.setMapRegisterCacheTimeout(90000);
+ Mockito.when(mockLispSouthboundPlugin.getMapRegisterCacheTimeout()).thenReturn(CACHE_RECORD_TIMEOUT);
mapRegisterCache = new MapRegisterCache();
- testedLispService.setMapRegisterCache(mapRegisterCache);
- testedLispService.setDataBroker(Mockito.mock(DataBroker.class));
- testedLispService.setAuthKeyDb(akdb);
- testedLispService.setAuthenticationKeyDataListener(akdl);
- nps = context.mock(NotificationPublishService.class);
- testedLispService.setNotificationProvider(nps);
- lispSouthboundStats = new ConcurrentLispSouthboundStats();
- testedLispService.setStats(lispSouthboundStats);
- lispNotificationSaver = new ValueSaverAction<Notification>();
- // mapRegisterSaver = new ValueSaverAction<MapRegister>();
- // mapRequestSaver = new ValueSaverAction<MapRequest>();
+ Mockito.when(mockLispSouthboundPlugin.getMapRegisterCache()).thenReturn(mapRegisterCache);
+ Mockito.when(mockLispSouthboundPlugin.getDataBroker()).thenReturn(Mockito.mock(DataBroker.class));
+ Mockito.when(mockLispSouthboundPlugin.getAkdb()).thenReturn(akdb);
+ Mockito.when(mockLispSouthboundPlugin.getAuthenticationKeyDataListener()).thenReturn(akdl);
+ ConcurrentLispSouthboundStats lispSouthboundStats = new ConcurrentLispSouthboundStats();
+ Mockito.when(mockLispSouthboundPlugin.getStats()).thenReturn(lispSouthboundStats);
+ testedLispService = new LispSouthboundHandler(mockLispSouthboundPlugin);
+
// SRC: 127.0.0.1:58560 to 127.0.0.1:4342
// LISP(Type = 8 - Encapsulated)
// IP: 192.168.136.10 -> 1.2.3.4
handleMapRequestPacket(mapRequestPacket);
}
- private MapRegister lastMapRegister() {
- assertTrue(lispNotificationSaver.lastValue instanceof AddMapping);
- AddMapping lastValue = (AddMapping) lispNotificationSaver.lastValue;
- return lastValue.getMapRegister();
- }
-
- private MapRequest lastMapRequest() {
- RequestMapping lastValue = (RequestMapping) lispNotificationSaver.lastValue;
- return lastValue.getMapRequest();
- }
-
@Test
public void mapRegister__TwoRlocs() throws Exception {
// P Bit & M Bit set
+ "0060 ff 00 00 05 00 01 0a 01 00 6e 06 64 ff 00 00 05 "
+ "0070 00 01 c0 a8 88 33"));
- oneOf(nps).putNotification(with(lispNotificationSaver));
-
+ ArgumentCaptor<AddMapping> captor = ArgumentCaptor.forClass(AddMapping.class);
handleMapRegisterPacket(mapRegisterPacket);
+ Mockito.verify(mockLispSouthboundPlugin).sendNotificationIfPossible(captor.capture());
- List<MappingRecordItem> eidRecords = lastMapRegister().getMappingRecordItem();
+ List<MappingRecordItem> eidRecords = captor.getValue().getMapRegister().getMappingRecordItem();
assertEquals(1, eidRecords.size());
MappingRecord eidRecord = eidRecords.get(0).getMappingRecord();
assertEquals(2, eidRecord.getLocatorRecord().size());
+ "0060 01 92 00 00 00 00 00 00 00 01 01 64 ff 00 00 05 "
+ "0070 00 01 0a 00 3a 9c"));
- oneOf(nps).putNotification(with(lispNotificationSaver));
-
+ ArgumentCaptor<AddMapping> captor = ArgumentCaptor.forClass(AddMapping.class);
handleMapRegisterPacket(mapRegisterPacket);
+ Mockito.verify(mockLispSouthboundPlugin).sendNotificationIfPossible(captor.capture());
+ MappingRecord eidToLocatorRecord =
+ captor.getValue().getMapRegister().getMappingRecordItem().get(0).getMappingRecord();
- MappingRecord eidToLocatorRecord = lastMapRegister().getMappingRecordItem().get(0).getMappingRecord();
assertEquals(LispAddressUtil.asIpv6PrefixBinaryEid("2610:d0:ffff:192:0:0:0:1/128"),
eidToLocatorRecord.getEid());
assertEquals(Ipv6PrefixBinaryAfi.class, eidToLocatorRecord.getEid().getAddressType());
@Test
public void mapRegister__VerifyBasicFields() throws Exception {
- oneOf(nps).putNotification(with(lispNotificationSaver));
+ ArgumentCaptor<AddMapping> captor = ArgumentCaptor.forClass(AddMapping.class);
handleMapRegisterPacket(mapRegisterPacket);
+ Mockito.verify(mockLispSouthboundPlugin).sendNotificationIfPossible(captor.capture());
+ MappingRecord eidToLocator =
+ captor.getValue().getMapRegister().getMappingRecordItem().get(0).getMappingRecord();
- MappingRecord eidToLocator = lastMapRegister().getMappingRecordItem().get(0).getMappingRecord();
assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid("153.16.254.1/32"), eidToLocator.getEid());
-
assertEquals(1, eidToLocator.getLocatorRecord().size());
assertEquals(LispAddressUtil.asIpv4Rloc("192.168.136.10"), eidToLocator.getLocatorRecord().get(0).getRloc());
}
@Test
- @Ignore
public void mapRegister__NoResponseFromMapServerShouldReturnNullPacket() throws Exception {
- oneOf(nps).putNotification(with(lispNotificationSaver));
mapNotifyBuilder = null;
-
assertNull(handleMapRegisterPacket(mapRegisterPacket));
}
+ "0040 83 63 a7 79 6e f0 40 97 54 26 3a 44 b4 eb 00 00 "
+ "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 "
+ "0060 ff 00 00 05 00 01 c0 a8 88 0a"));
- stubMapRegister(true);
+ ArgumentCaptor<AddMapping> captor = ArgumentCaptor.forClass(AddMapping.class);
handleMapRegisterPacket(registerWithNonSetMBit);
-
- assertFalse(lastMapRegister().isWantMapNotify());
+ Mockito.verify(mockLispSouthboundPlugin).sendNotificationIfPossible(captor.capture());
+ assertFalse(captor.getValue().getMapRegister().isWantMapNotify());
}
@Test
+ "0040 e7 20 25 3d e8 b2 07 e2 63 de 62 2b 7a 20 00 00 "
+ "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 "
+ "0060 ff 00 00 05 00 01 c0 a8 88 0a"));
- stubMapRegister(true);
+ ArgumentCaptor<AddMapping> captor = ArgumentCaptor.forClass(AddMapping.class);
handleMapRegisterPacket(registerWithNonSetMBit);
- assertFalse(lastMapRegister().isWantMapNotify());
+ Mockito.verify(mockLispSouthboundPlugin).sendNotificationIfPossible(captor.capture());
+ assertFalse(captor.getValue().getMapRegister().isWantMapNotify());
}
@Test
+ "0040 4e 6b e2 e5 e1 01 40 8a c9 e1 d1 80 cb 72 00 00 "
+ "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 "
+ "0060 ff 00 00 05 00 01 c0 a8 88 0a"));
- stubMapRegister(true);
+ ArgumentCaptor<AddMapping> captor = ArgumentCaptor.forClass(AddMapping.class);
handleMapRegisterPacket(registerWithNonSetMBit);
- assertTrue(lastMapRegister().isWantMapNotify());
+ Mockito.verify(mockLispSouthboundPlugin).sendNotificationIfPossible(captor.capture());
+ assertTrue(captor.getValue().getMapRegister().isWantMapNotify());
}
/**
0x0a, 0x0a, 0x0a, 0x0a //ipv4 address
};
- NotificationPublishService notifServiceMock = MapRegisterCacheTestUtil.resetMockForNotificationProvider(
- testedLispService);
-
//send stream of byte -> map register message
+ InOrder inOrder = Mockito.inOrder(mockLispSouthboundPlugin);
final MapRegisterCacheKey cacheKey = MapRegisterCacheTestUtil.createMapRegisterCacheKey(eidPrefix);
MapRegisterCacheTestUtil.beforeMapRegisterInvocationValidation(cacheKey, mapRegisterCache);
+ ArgumentCaptor<AddMapping> captor = ArgumentCaptor.forClass(AddMapping.class);
mapRegisterInvocationForCacheTest(eidPrefixAfi, eidPrefix);
- MapRegisterCacheTestUtil.afterMapRegisterInvocationValidation(notifServiceMock,
+ inOrder.verify(mockLispSouthboundPlugin).sendNotificationIfPossible(captor.capture());
+ MapRegisterCacheTestUtil.afterMapRegisterInvocationValidation(
cacheKey, mapRegisterCache, eidPrefixAfi, eidPrefix);
//sending the same byte stream -> map register second time
- notifServiceMock = MapRegisterCacheTestUtil.resetMockForNotificationProvider(testedLispService);
+ captor = ArgumentCaptor.forClass(AddMapping.class);
mapRegisterInvocationForCacheTest(eidPrefixAfi, eidPrefix);
+ inOrder.verify(mockLispSouthboundPlugin).sendNotificationIfPossible(captor.capture());
//mapping-keep-alive message should be generated
- MapRegisterCacheTestUtil.afterSecondMapRegisterInvocationValidation(notifServiceMock,
+ MapRegisterCacheTestUtil.afterSecondMapRegisterInvocationValidation(
mockLispSouthboundPlugin, eidPrefixAfi, eidPrefix);
}
InterruptedException {
final MapRegisterCacheKey mapRegisterCacheKey = MapRegisterCacheTestUtil.createMapRegisterCacheKey(eidPrefix);
- final NotificationPublishService mockedNotificationProvider = mock(NotificationPublishService.class);
- testedLispService.setNotificationProvider(mockedNotificationProvider);
-
MapRegisterCacheTestUtil.beforeMapRegisterInvocationValidation(mapRegisterCacheKey, mapRegisterCache);
+ ArgumentCaptor<AddMapping> captor = ArgumentCaptor.forClass(AddMapping.class);
mapRegisterInvocationForCacheTest(eidPrefixAfi, eidPrefix, authenticationData);
- MapRegisterCacheTestUtil.afterMapRegisterInvocationValidation(mockedNotificationProvider,
+ Mockito.verify(mockLispSouthboundPlugin).sendNotificationIfPossible(captor.capture());
+ MapRegisterCacheTestUtil.afterMapRegisterInvocationValidation(
mapRegisterCacheKey, mapRegisterCache, eidPrefixAfi, eidPrefix);
}
private void cacheRecordExpirationTest(boolean cacheRecordTimeouted) throws InterruptedException {
mapRegisterCache = Mockito.mock(MapRegisterCache.class);
- testedLispService.setMapRegisterCache(mapRegisterCache);
- testedLispService.setNotificationProvider(Mockito.mock(NotificationPublishService.class));
+ Mockito.when(mockLispSouthboundPlugin.getMapRegisterCache()).thenReturn(mapRegisterCache);
final byte[] eidPrefixAfi = new byte[] {0x00, 0x01};
final byte[] eidPrefix = new byte[] {0x0a, 0x0a, 0x0a, 0x0a};
Mockito.when(mapRegisterCache.refreshEntry(Mockito.eq(cacheKey))).thenReturn(cacheValue);
mapRegisterInvocationForCacheTest(eidPrefixAfi, eidPrefix);
+ Mockito.verify(mockLispSouthboundPlugin, Mockito.atLeastOnce()).sendNotificationIfPossible(
+ Mockito.any(AddMapping.class));
InOrder inOrder = Mockito.inOrder(mapRegisterCache);
inOrder.verify(mapRegisterCache).getEntry(Mockito.eq(cacheKey));
byte[] extraDataPacket = new byte[mapRegisterPacket.length + 3];
extraDataPacket[mapRegisterPacket.length] = 0x9;
System.arraycopy(mapRegisterPacket, 0, extraDataPacket, 0, mapRegisterPacket.length);
- stubMapRegister(true);
DatagramPacket dp = new DatagramPacket(wrappedBuffer(extraDataPacket), new InetSocketAddress(0),
new InetSocketAddress(0));
byte registerType = mapRegisterPacket[0];
assertEquals(MessageType.MapRegister.getIntValue(), registerType >> 4);
- stubMapRegister(true);
-
byte[] result = handleMapRegisterAsByteArray(mapRegisterPacket);
assertEquals(mapRegisterPacket.length, result.length);
@Ignore
@Test
public void mapNotify__VerifyPort() throws Exception {
- stubMapRegister(true);
-
DatagramPacket notifyPacket = handleMapRegisterPacket(mapRegisterPacket);
assertEquals(LispMessage.PORT_NUM, notifyPacket.recipient().getPort());
}
@Test
public void mapRequest__VerifyBasicFields() throws Exception {
- oneOf(nps).putNotification(with(lispNotificationSaver));
+ ArgumentCaptor<RequestMapping> captor = ArgumentCaptor.forClass(RequestMapping.class);
handleMapRequestAsByteArray(mapRequestPacket);
- List<EidItem> eids = lastMapRequest().getEidItem();
+ Mockito.verify(mockLispSouthboundPlugin).sendNotificationIfPossible(captor.capture());
+ List<EidItem> eids = captor.getValue().getMapRequest().getEidItem();
assertEquals(1, eids.size());
Eid lispAddress = eids.get(0).getEid();
assertEquals(Ipv4PrefixBinaryAfi.class, lispAddress.getAddressType());
assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32"), lispAddress);
- assertEquals(0x3d8d2acd39c8d608L, lastMapRequest().getNonce().longValue());
+ assertEquals(0x3d8d2acd39c8d608L, captor.getValue().getMapRequest().getNonce().longValue());
}
@Test
+ "00a0 00 02 26 10 00 d0 ff ff 01 92 00 00 00 00 00 00 "
+ "00b0 00 01 01 64 ff 00 00 05 00 01 0a 00 3a 9c"));
- oneOf(nps).putNotification(with(lispNotificationSaver));
- // ret(mapReply);
-
+ ArgumentCaptor<RequestMapping> captor = ArgumentCaptor.forClass(RequestMapping.class);
handleMapRequestAsByteArray(mapRequestPacket);
- assertEquals(LispAddressUtil.asIpv6Eid("2610:d0:ffff:192:0:0:0:1"), lastMapRequest().getSourceEid().getEid());
+ Mockito.verify(mockLispSouthboundPlugin).sendNotificationIfPossible(captor.capture());
+ assertEquals(LispAddressUtil.asIpv6Eid("2610:d0:ffff:192:0:0:0:1"),
+ captor.getValue().getMapRequest().getSourceEid().getEid());
assertEquals(LispAddressUtil.asIpv6PrefixBinaryEid("2610:d0:ffff:192:0:0:0:2/128"),
- lastMapRequest().getEidItem().get(0).getEid());
+ captor.getValue().getMapRequest().getEidItem().get(0).getEid());
}
@Ignore
+ "0090 00 00 00 00 00 02 00 00 00 0a 01 80 10 00 00 00 "
+ "00a0 00 02 26 10 00 d0 ff ff 01 92 00 00 00 00 00 00 "
+ "00b0 00 01 01 64 ff 00 00 05 00 01 0a 00 3a 9c"));
- oneOf(nps).putNotification(with(lispNotificationSaver));
- // ret(mapReply);
+ ArgumentCaptor<RequestMapping> captor = ArgumentCaptor.forClass(RequestMapping.class);
DatagramPacket replyPacket = handleMapRequestPacket(mapRequestPacket);
+ Mockito.verify(mockLispSouthboundPlugin).sendNotificationIfPossible(Mockito.any());
assertEquals(4342, replyPacket.recipient().getPort());
}
+ "0070 10 00 00 00 00 01 99 10 fe 01 01 64 ff 00 00 05 "
+ "0080 00 01 0a 00 01 26"));
- oneOf(nps).putNotification(with(lispNotificationSaver));
- // ret(mapReply);
-
+ ArgumentCaptor<RequestMapping> captor = ArgumentCaptor.forClass(RequestMapping.class);
handleMapRequestAsByteArray(mapRequestPacket);
- assertEquals(Ipv4BinaryAfi.class, lastMapRequest().getSourceEid().getEid().getAddressType());
+ Mockito.verify(mockLispSouthboundPlugin).sendNotificationIfPossible(captor.capture());
+ assertEquals(Ipv4BinaryAfi.class, captor.getValue().getMapRequest().getSourceEid().getEid().getAddressType());
}
@Test
@Ignore
- public void mapReply__VerifyBasicIPv6() throws Exception {
+ public void mapReply_q_VerifyBasicIPv6() throws Exception {
mappingRecordBuilder.setEid(LispAddressUtil.asIpv6PrefixEid("0:0:0:0:0:0:0:1/128"));
stubHandleRequest();
+ "0080 01 64 ff 00 00 05 00 01 0a 01 00 6f 06 64 ff 00 "
+ "0090 00 05 00 01 c0 a8 88 33"));
- oneOf(nps).putNotification(with(lispNotificationSaver));
handleMapRequestAsByteArray(mapRequestPacket);
-
- }
-
- private void stubMapRegister(final boolean setNotifyFromRegister) {
- try {
- allowing(nps).putNotification(with(lispNotificationSaver));
- } catch (InterruptedException e) {
- LOG.debug("Interrupted", e);
- }
- will(new SimpleAction() {
-
- @Override
- public Object invoke(Invocation invocation) throws Throwable {
- if (setNotifyFromRegister) {
- MapNotifyBuilderHelper.setFromMapRegister(mapNotifyBuilder, lastMapRegister());
- }
- return null;
- }
- });
+ Mockito.verify(mockLispSouthboundPlugin).sendNotificationIfPossible(Mockito.any(RequestMapping.class));
}
private void stubHandleRequest() {
try {
- allowing(nps).putNotification(wany(Notification.class));
+ allowing(contextMockLispSouthboundPlugin).sendNotificationIfPossible(wany(Notification.class));
} catch (InterruptedException e) {
LOG.debug("Interrupted", e);
}
+ "00 20 00 01 01 02 03 04").array();
handleMapRequestPacket(mapRequestPacket);
}
-
- // @Ignore
- // @Test
- // public void mapRequest__IPITRRLOCIsSecond() throws Exception {
- // mapRequestPacket = hexToByteBuffer("10 00 " //
- // + "01 " // This means 3 ITR - RLOCs
- // + "01 3d 8d 2a cd 39 c8 d6 08 00 00 " //
- // + "40 05 c0 a8 88 0a 01 02 " // MAC (ITR-RLOC #1 of 2)
- // + "00 01 01 02 03 04 " // IP (ITR-RLOC #2 of 2)
- // + "00 20 00 01 01 02 03 04").array();
- // oneOf(nps).putNotification(with(lispNotificationSaver));
- // // ret(mapReply);
- // DatagramPacket packet = handleMapRequestPacket(mapRequestPacket);
- // assertEquals(2, lastMapRequest().getItrRlocs().size());
- // assertEquals((new LispIpv4Address("1.2.3.4")).getAddress(),
- // packet.getAddress());
- // }
- //
- // @Ignore
- // @Test
- // public void mapRequest__MULTIPLEIPITRRLOCs() throws Exception {
- // mapRequestPacket = hexToByteBuffer("10 00 " //
- // + "01 " // This means 3 ITR - RLOCs
- // + "01 3d 8d 2a cd 39 c8 d6 08 00 00 " //
- // + "00 01 01 02 03 04 " // IP (ITR-RLOC #1 of 2)
- // + "00 01 c0 a8 88 0a " // MAC (ITR-RLOC #2 of 2)
- // + "00 20 00 01 01 02 03 04").array();
- // oneOf(nps).putNotification(with(lispNotificationSaver));
- // // ret(mapReply);
- // DatagramPacket packet = handleMapRequestPacket(mapRequestPacket);
- // assertEquals(2, lastMapRequest().getItrRloc().size());
- // assertEquals((new LispIpv4Address("1.2.3.4")).getAddress(),
- // packet.getAddress());
- // }
-
}
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.Arrays;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
+import org.opendaylight.lispflowmapping.southbound.LispSouthboundPlugin;
import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.Ipv4AddressBinary;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv4BinaryAfi;
@RunWith(MockitoJUnitRunner.class)
public class LispXtrSouthboundHandlerTest {
- @Mock(name = "notificationPublishService") private static NotificationPublishService notificationPublishServiceMock;
- @InjectMocks private static LispXtrSouthboundHandler handler;
-
private static final String IPV4_STRING_1 = "1.2.3.4";
private static final String IPV4_STRING_2 = "127.0.0.1";
private static final String IPV4_STRING_PREFIX = "/32";
+ "0060 00 01 01 02 03 04 00 00 00 00 00 00 00 01 fe fe "
+ "0070 fe fe 0d e3 70 40";
+ private LispSouthboundPlugin lispSbPluginMock;
+ private LispXtrSouthboundHandler handler;
+
+ @Before
+ public void initTest() {
+ lispSbPluginMock = Mockito.mock(LispSouthboundPlugin.class);
+ handler = new LispXtrSouthboundHandler(lispSbPluginMock);
+ }
+
/**
* Tests {@link LispXtrSouthboundHandler#handlePacket} method with Map-Request.
*/
handler.handlePacket(extractLispPacket(MAP_REQUEST_PACKET_STRING, HEADER_LENGTH,
LISP_MAP_REQUEST_PACKET_LENGTH));
- Mockito.verify(notificationPublishServiceMock).putNotification(captor.capture());
+ Mockito.verify(lispSbPluginMock).sendNotificationIfPossible(captor.capture());
assertEquals(expectedRequest, captor.getValue().getMapRequest());
}
- /**
- * Tests {@link LispXtrSouthboundHandler#handlePacket} method with Map-Request, null NotificationPublishService.
- */
- @Test
- public void handlePacketTest_withMapRequest_withNullNotifPublishService() throws InterruptedException {
- final LispXtrSouthboundHandler handler = new LispXtrSouthboundHandler();
- handler.handlePacket(extractLispPacket(MAP_REQUEST_PACKET_STRING, HEADER_LENGTH,
- LISP_MAP_REQUEST_PACKET_LENGTH));
- Mockito.verifyZeroInteractions(notificationPublishServiceMock);
- }
-
/**
* Tests {@link LispXtrSouthboundHandler#handlePacket} method with Map-Request, no Itr Rlocs.
*/
handler.handlePacket(extractLispPacket(MAP_REPLY_PACKET_STRING, HEADER_LENGTH,
LISP_MAP_REPLY_PACKET_LENGTH));
- Mockito.verify(notificationPublishServiceMock).putNotification(captor.capture());
+ Mockito.verify(lispSbPluginMock).sendNotificationIfPossible(captor.capture());
assertNotNull(captor.getValue().getMapReply());
}
- /**
- * Tests {@link LispXtrSouthboundHandler#handlePacket} method with Map-Reply over channelRead0 method.
- */
- @Test
- public void handlePacketTest_withMapReply_withNullNotifPublishService() throws Exception {
- final LispXtrSouthboundHandler handler = new LispXtrSouthboundHandler();
- handler.channelRead0(Mockito.mock(ChannelHandlerContext.class),
- extractLispPacket(MAP_REPLY_PACKET_STRING, HEADER_LENGTH, LISP_MAP_REPLY_PACKET_LENGTH));
-
- Mockito.verifyZeroInteractions(notificationPublishServiceMock);
- }
-
/**
* Tests {@link LispXtrSouthboundHandler#channelReadComplete} method.
*/
+ "0070 fe fe 0d e3 70 40";
handler.exceptionCaught(Mockito.mock(ChannelHandlerContext.class), Mockito.mock(Throwable.class));
- handler.setNotificationProvider(notificationPublishServiceMock);
handler.handlePacket(extractLispPacket(mapNotificationPacket, HEADER_LENGTH, LISP_MAP_REPLY_PACKET_LENGTH));
}
.setSmr(false)
.setSmrInvoked(false);
}
-}
+}
\ No newline at end of file
*/
package org.opendaylight.lispflowmapping.southbound.lisp;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import java.net.Inet4Address;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.Assert;
import org.mockito.Mockito;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
import org.opendaylight.lispflowmapping.southbound.LispSouthboundPlugin;
import org.opendaylight.lispflowmapping.southbound.lisp.cache.MapRegisterCache;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.AddMapping;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MappingKeepAlive;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MessageType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.key.container.MapRegisterCacheKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.key.container.MapRegisterCacheKeyBuilder;
return result;
}
- static NotificationPublishService resetMockForNotificationProvider(final LispSouthboundHandler testedLispService) {
- NotificationPublishService mockedNotificationProvider = mock(NotificationPublishService.class);
- testedLispService.setNotificationProvider(mockedNotificationProvider);
- return mockedNotificationProvider;
- }
-
- static void afterSecondMapRegisterInvocationValidation(final NotificationPublishService
- mockedNotificationProvider,
- final LispSouthboundPlugin mockLispSouthboundPlugin,
+ static void afterSecondMapRegisterInvocationValidation(final LispSouthboundPlugin mockLispSouthboundPlugin,
byte[] eidPrefixAfi, byte[] eidPrefix) throws
InterruptedException, UnknownHostException {
- verify(mockedNotificationProvider).putNotification(Mockito.any(MappingKeepAlive.class));
-
final byte[] resetForMapNotify = new byte[]{
0x4C, 0x00, 0x00, 0x01
};
Mockito.eq(null));
}
- static void afterMapRegisterInvocationValidation(final NotificationPublishService mockedNotificationProvider, final
- MapRegisterCacheKey mapRegisterCacheKey, final MapRegisterCache mapRegisterCache, final byte[] eidPrefixAfi,
- byte[] eidPrefix) throws InterruptedException {
- Mockito.verify(mockedNotificationProvider).putNotification(Mockito.any(AddMapping.class));
-
+ static void afterMapRegisterInvocationValidation(final MapRegisterCacheKey mapRegisterCacheKey,
+ final MapRegisterCache mapRegisterCache, final byte[] eidPrefixAfi, byte[] eidPrefix)
+ throws InterruptedException {
Assert.assertEquals(1, mapRegisterCache.cacheSize());
final MapRegisterCacheValue currentMapRegisterCacheValue = mapRegisterCache.getEntry(mapRegisterCacheKey);
Assert.assertNotNull(currentMapRegisterCacheValue);