import java.math.BigInteger;
import java.net.InetSocketAddress;
import java.util.concurrent.atomic.AtomicLong;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
import org.opendaylight.openflowplugin.api.openflow.device.Xid;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry;
import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
-import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
import org.opendaylight.openflowplugin.extension.api.ConvertorMessageFromOFJava;
import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
import org.opendaylight.openflowplugin.impl.registry.flow.FlowDescriptorFactory;
import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory;
import org.opendaylight.openflowplugin.impl.util.DeviceStateUtil;
-import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.ExperimenterMessageFromDev;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
@Mock
HashedWheelTimer timer;
@Mock
- MessageIntelligenceAgency messageIntelligenceAgency;
- @Mock
OutboundQueueProvider outboundQueueProvider;
@Mock
ConnectionAdapter connectionAdapter;
@Mock
private MessageTranslator<Object, Object> messageTranslatorFlowRemoved;
@Mock
- private LifecycleConductor lifecycleConductor;
- @Mock
private DeviceInfo deviceInfo;
@Mock
private DeviceManager deviceManager;
+ @Mock
+ private ConvertorExecutor convertorExecutor;
+ @Mock
+ private MessageSpy messageSpy;
private InOrder inOrderDevState;
Mockito.when(translatorLibrary.lookupTranslator(eq(new TranslatorKey(OFConstants.OFP_VERSION_1_3,
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved.class.getName()))))
.thenReturn(messageTranslatorFlowRemoved);
- Mockito.when(lifecycleConductor.getMessageIntelligenceAgency()).thenReturn(messageIntelligenceAgency);
- deviceContext = new DeviceContextImpl(connectionContext, deviceState, dataBroker, lifecycleConductor, outboundQueueProvider, translatorLibrary, deviceManager);
+ deviceContext = new DeviceContextImpl(
+ connectionContext,
+ dataBroker,
+ messageSpy,
+ translatorLibrary,
+ deviceManager,
+ convertorExecutor,
+ false, timer, deviceManager);
deviceContextSpy = Mockito.spy(deviceContext);
xid = new Xid(atomicLong.incrementAndGet());
xidMulti = new Xid(atomicLong.incrementAndGet());
+ ((DeviceContextImpl) deviceContext).lazyTransactionManagerInitialization();
Mockito.doNothing().when(deviceContextSpy).writeToTransaction(Mockito.<LogicalDatastoreType>any(), Mockito.<InstanceIdentifier>any(), any());
- }
- @Test(expected = NullPointerException.class)
- public void testDeviceContextImplConstructorNullDataBroker() throws Exception {
- new DeviceContextImpl(connectionContext, deviceState, null, lifecycleConductor, outboundQueueProvider, translatorLibrary, deviceManager).close();
}
@Test(expected = NullPointerException.class)
- public void testDeviceContextImplConstructorNullDeviceState() throws Exception {
- new DeviceContextImpl(connectionContext, null, dataBroker, lifecycleConductor, outboundQueueProvider, translatorLibrary, deviceManager).close();
+ public void testDeviceContextImplConstructorNullDataBroker() throws Exception {
+ new DeviceContextImpl(connectionContext, null, null, translatorLibrary, deviceManager, convertorExecutor,false, timer, deviceManager).close();
}
@Test(expected = NullPointerException.class)
public void testDeviceContextImplConstructorNullTimer() throws Exception {
- new DeviceContextImpl(null, deviceState, dataBroker, lifecycleConductor, outboundQueueProvider, translatorLibrary, deviceManager).close();
- }
-
- @Test
- public void testGetDeviceState() {
- final DeviceState deviceSt = deviceContext.getDeviceState();
- assertNotNull(deviceSt);
- assertEquals(deviceState, deviceSt);
+ new DeviceContextImpl(null, dataBroker, null, translatorLibrary, deviceManager,convertorExecutor,false, timer, deviceManager).close();
}
@Test
((DeviceContextImpl) deviceContext).getTransactionChainManager().activateTransactionManager() ;
((DeviceContextImpl) deviceContext).getTransactionChainManager().enableSubmit();
deviceContext.addDeleteToTxChain(LogicalDatastoreType.CONFIGURATION, dummyII);
- ((DeviceContextImpl) deviceContext).initialSubmitTransaction();
+ deviceContext.initialSubmitTransaction();
verify(wTx).submit();
}
- @Test
- public void testGetReservedXid() {
- deviceContext.reserveXidForDeviceMessage();
- verify(outboundQueueProvider).reserveEntry();
- }
-
@Test
public void testAuxiliaryConnectionContext() {
final ConnectionContext mockedConnectionContext = addDummyAuxiliaryConnectionContext();
- final ConnectionContext pickedConnectiobContexts = deviceContext.getAuxiliaryConnectiobContexts(DUMMY_COOKIE);
+ final ConnectionContext pickedConnectiobContexts = deviceContext.getAuxiliaryConnectionContexts(DUMMY_COOKIE);
assertEquals(mockedConnectionContext, pickedConnectiobContexts);
}
@Test
final ConnectionAdapter mockedAuxConnectionAdapter = mock(ConnectionAdapter.class);
when(mockedConnectionContext.getConnectionAdapter()).thenReturn(mockedAuxConnectionAdapter);
- assertNotNull(deviceContext.getAuxiliaryConnectiobContexts(DUMMY_COOKIE));
+ assertNotNull(deviceContext.getAuxiliaryConnectionContexts(DUMMY_COOKIE));
deviceContext.removeAuxiliaryConnectionContext(mockedConnectionContext);
- assertNull(deviceContext.getAuxiliaryConnectiobContexts(DUMMY_COOKIE));
+ assertNull(deviceContext.getAuxiliaryConnectionContexts(DUMMY_COOKIE));
}
private ConnectionContext addDummyAuxiliaryConnectionContext() {
public void testProcessReply() {
final Error mockedError = mock(Error.class);
deviceContext.processReply(mockedError);
- verify(messageIntelligenceAgency).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_FAILURE));
+ verify(messageSpy).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_FAILURE));
final OfHeader mockedOfHeader = mock(OfHeader.class);
deviceContext.processReply(mockedOfHeader);
- verify(messageIntelligenceAgency).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS));
+ verify(messageSpy).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS));
}
@Test
final MultipartReply mockedMultipartReply = mock(MultipartReply.class);
final Xid dummyXid = new Xid(DUMMY_XID);
deviceContext.processReply(dummyXid, Lists.newArrayList(mockedMultipartReply));
- verify(messageIntelligenceAgency).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_FAILURE));
+ verify(messageSpy).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_FAILURE));
}
@Test
when(mockedNotificationPublishService.offerNotification(any(PacketReceived.class))).thenReturn(stringListenableFuture);
deviceContext.setNotificationPublishService(mockedNotificationPublishService);
deviceContext.processPacketInMessage(mockedPacketInMessage);
- verify(messageIntelligenceAgency).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS));
+ verify(messageSpy).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS));
}
@Test
when(mockedNotificationPublishService.offerNotification(any(PacketReceived.class))).thenReturn(dummyFuture);
deviceContext.setNotificationPublishService(mockedNotificationPublishService);
deviceContext.processPacketInMessage(mockedPacketInMessage);
- verify(messageIntelligenceAgency).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_NOTIFICATION_REJECTED));
+ verify(messageSpy).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_NOTIFICATION_REJECTED));
}
@Test
final ConnectionContext mockedAuxiliaryConnectionContext = prepareConnectionContext();
deviceContext.addAuxiliaryConnectionContext(mockedAuxiliaryConnectionContext);
- final DeviceTerminationPhaseHandler mockedDeviceContextClosedHandler = mock(DeviceTerminationPhaseHandler.class);
- when(deviceState.isValid()).thenReturn(true);
deviceContext.shutdownConnection();
verify(connectionContext).closeConnection(true);
}
@Test
public void testGetMessageSpy() {
final MessageSpy pickedMessageSpy = deviceContext.getMessageSpy();
- assertEquals(messageIntelligenceAgency, pickedMessageSpy);
+ assertEquals(messageSpy, pickedMessageSpy);
}
@Test
when(mockedPortStatusMessage.getReason()).thenReturn(PortReason.OFPPRADD);
when(mockedPortStatusMessage.getPortNo()).thenReturn(42L);
- OpenflowPortsUtil.init();
deviceContextSpy.processPortStatusMessage(mockedPortStatusMessage);
verify(deviceContextSpy).writeToTransaction(Mockito.<LogicalDatastoreType>any(), Mockito.<InstanceIdentifier>any(), any());
verify(deviceContextSpy).submitTransaction();
.thenReturn(flowRemovedMdsalBld.build());
// insert flow+flowId into local registry
- final FlowRegistryKey flowRegKey = FlowRegistryKeyFactory.create(flowRemovedMdsalBld.build());
+ final FlowRegistryKey flowRegKey = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flowRemovedMdsalBld.build());
final FlowDescriptor flowDescriptor = FlowDescriptorFactory.create((short) 0, new FlowId("ut-ofp:f456"));
deviceContext.getDeviceFlowRegistry().store(flowRegKey, flowDescriptor);
.child(Table.class, new TableKey((short) 0))
.child(Flow.class, new FlowKey(new FlowId("ut-ofp:f456")));
- Mockito.when(deviceManager.getIsNotificationFlowRemovedOff()).thenReturn(true);
+ Mockito.when(deviceManager.isFlowRemovedNotificationOn()).thenReturn(true);
deviceContext.setNotificationPublishService(mockedNotificationPublishService);
deviceContext.processFlowRemovedMessage(flowRemovedBld.build());
Mockito.verify(itemLifecycleListener).onRemoved(flowToBeRemovedPath);
- Mockito.verify(mockedNotificationPublishService, Mockito.never()).offerNotification(Matchers.any(Notification.class));
- Mockito.when(deviceManager.getIsNotificationFlowRemovedOff()).thenReturn(false);
+ Mockito.when(deviceManager.isFlowRemovedNotificationOn()).thenReturn(false);
deviceContext.processFlowRemovedMessage(flowRemovedBld.build());
Mockito.verify(mockedNotificationPublishService).offerNotification(Matchers.any(Notification.class));
assertEquals(0, deviceContext.getDeviceMeterRegistry().getAllMeterIds().size());
}
+
+ @Test
+ public void replaceConnectionContext() throws Exception {
+
+ final ConnectionContext connectionContext1 = mock(ConnectionContext.class);
+ Assert.assertEquals(deviceContext.getPrimaryConnectionContext(), connectionContext);
+ Mockito.when(connectionContext1.getConnectionAdapter()).thenReturn(connectionAdapter);
+ Mockito.doNothing().when(connectionAdapter).setPacketInFiltering(Mockito.anyBoolean());
+ deviceContext.replaceConnectionContext(connectionContext1);
+ Assert.assertEquals(deviceContext.getPrimaryConnectionContext(), connectionContext1);
+
+ }
+
}