import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-
+import static org.junit.Assert.assertNull;
import com.google.common.util.concurrent.Futures;
-
+import com.google.common.util.concurrent.ListeningExecutorService;
import java.math.BigInteger;
import java.util.Collections;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.controller.sal.binding.api.NotificationListener;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
-import org.opendaylight.controller.sal.common.util.Rpcs;
-import org.opendaylight.openflowplugin.openflow.md.ModelDrivenSwitch;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.openflowplugin.api.OFConstants;
-import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor;
-import org.opendaylight.openflowplugin.openflow.md.core.NotificationEnqueuer;
+import org.opendaylight.openflowplugin.api.openflow.md.ModelDrivenSwitch;
+import org.opendaylight.openflowplugin.api.openflow.md.core.ConnectionConductor;
+import org.opendaylight.openflowplugin.api.openflow.md.core.NotificationEnqueuer;
import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
-import org.opendaylight.openflowplugin.openflow.md.core.session.IMessageDispatchService;
-import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
-import org.opendaylight.openflowplugin.openflow.md.core.session.SwitchSessionKeyOF;
+import org.opendaylight.openflowplugin.api.openflow.md.core.session.IMessageDispatchService;
+import org.opendaylight.openflowplugin.api.openflow.md.core.session.SwitchSessionKeyOF;
+import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
+import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContextOFImpl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
import org.opendaylight.yangtools.concepts.CompositeObjectRegistration;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.Notification;
-import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.opendaylight.openflowplugin.openflow.md.core.role.OfEntityManager;
+import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
/**
* Created by Martin Bobak mbobak@cisco.com on 8/26/14.
private static final BigInteger dataPathId = BigInteger.ONE;
private SalRegistrationManager salRegistrationManager;
- @Mock
- private SessionContext context;
+
+ private SessionContextOFImpl context;
@Mock
private ConnectionConductor conductor;
@Mock
private BindingAwareBroker.ProviderContext providerContext;
@Mock
private NotificationEnqueuer notificationEnqueuer;
+ @Mock
+ private ListeningExecutorService rpcPool;
+ @Mock
+ private NotificationProviderService notificationProviderService;
+ @Mock
+ private RpcProviderRegistry rpcProviderRegistry;
+ @Mock
+ private DataBroker dataBroker;
+ @Mock
+ private EntityOwnershipService entityOwnershipService;
+
+ @Mock
+ private ModelDrivenSwitchImpl ofSwitch;
private ModelDrivenSwitch mdSwitchOF13;
+
CompositeObjectRegistration<ModelDrivenSwitch> registration;
+
@Before
public void setUp() {
-
- Mockito.when(context.getPrimaryConductor()).thenReturn(conductor);
- Mockito.when(context.getMessageDispatchService()).thenReturn(messageDispatchService);
+ OFSessionUtil.getSessionManager().setRpcPool(rpcPool);
Mockito.when(conductor.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_0)
.thenReturn(OFConstants.OFP_VERSION_1_3);
- Mockito.when(context.getFeatures()).thenReturn(features);
-
- mdSwitchOF13 = new ModelDrivenSwitchImpl(null, null, context);
- registration = new CompositeObjectRegistration<>(mdSwitchOF13, Collections.EMPTY_LIST);
-
- Mockito.when(context.getProviderRegistration()).thenReturn(registration);
- Mockito.when(context.getNotificationEnqueuer()).thenReturn(notificationEnqueuer);
+ context = new SessionContextOFImpl();
+ context.setPrimaryConductor(conductor);
Mockito.when(features.getDatapathId()).thenReturn(BigInteger.valueOf(1));
Mockito.when(features.getVersion()).thenReturn((short) 1);
+ context.setFeatures(features);
+ context.setNotificationEnqueuer(notificationEnqueuer);
+
+ OfEntityManager entManager = new OfEntityManager(entityOwnershipService);
+ mdSwitchOF13 = new ModelDrivenSwitchImpl(null, null, context);
+ registration = new CompositeObjectRegistration<>(mdSwitchOF13, Collections.<Registration>emptyList());
+ context.setProviderRegistration(registration);
- Set<RpcError> errorSet = Collections.emptySet();
UpdateFlowOutputBuilder updateFlowOutput = new UpdateFlowOutputBuilder();
- RpcResult<UpdateFlowOutput> result = Rpcs.getRpcResult(true, updateFlowOutput.build(), errorSet);
+ RpcResult<UpdateFlowOutput> result = RpcResultBuilder.success(updateFlowOutput.build()).build();
Mockito.when(
messageDispatchService.flowMod(Matchers.any(FlowModInput.class),
Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
salRegistrationManager = new SalRegistrationManager();
- salRegistrationManager.onSessionInitiated(providerContext);
- salRegistrationManager.setPublishService(new MockNotificationProviderService());
+ salRegistrationManager.setPublishService(notificationProviderService);
+ salRegistrationManager.setDataService(dataBroker);
+ salRegistrationManager.setRpcProviderRegistry(rpcProviderRegistry);
+ salRegistrationManager.setOfEntityManager(entManager);
+
+ salRegistrationManager.init();
+
+ }
+
+ /**
+ * free sesion manager
+ */
+ @After
+ public void tearDown() {
+ OFSessionUtil.releaseSessionManager();
}
/**
*/
@Test
public void testIdentifierFromDatapathId() {
- InstanceIdentifier<Node> node = salRegistrationManager.identifierFromDatapathId(dataPathId);
+ InstanceIdentifier<Node> node = SalRegistrationManager.identifierFromDatapathId(dataPathId);
assertNotNull(node);
- assertEquals("NodeKey [_id=Uri [_value=openflow:1]]", ((KeyedInstanceIdentifier) node).getKey().toString());
+ assertEquals("NodeKey [_id=Uri [_value=openflow:1]]", ((KeyedInstanceIdentifier<?, ?>) node).getKey().toString());
}
/**
*/
@Test
public void testNodeKeyFromDatapathId() {
- NodeKey nodeKey = salRegistrationManager.nodeKeyFromDatapathId(dataPathId);
+ NodeKey nodeKey = SalRegistrationManager.nodeKeyFromDatapathId(dataPathId);
assertNotNull(nodeKey);
assertEquals("openflow:1", nodeKey.getId().getValue());
}
*/
@Test
public void testNodeIdFromDatapathId() {
- NodeId nodeId = salRegistrationManager.nodeIdFromDatapathId(dataPathId);
+ NodeId nodeId = SalRegistrationManager.nodeIdFromDatapathId(dataPathId);
assertNotNull(nodeId);
assertEquals("openflow:1", nodeId.getValue());
}
/**
- * Test for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.SalRegistrationManager#onSessionRemoved(org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext)}
+ * Test for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.SalRegistrationManager#onSessionRemoved(org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext)}
*/
@Test
public void testOnSessionRemoved() {
- salRegistrationManager.onSessionRemoved(context);
+// assertNotNull(context.getProviderRegistration());
+// salRegistrationManager.onSessionAdded(null,context);
+// salRegistrationManager.onSessionRemoved(context);
+// assertNull(context.getProviderRegistration());
}
/**
- * Test for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.SalRegistrationManager#onSessionAdded(org.opendaylight.openflowplugin.openflow.md.core.session.SwitchSessionKeyOF, org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext)}
+ * Test for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.SalRegistrationManager#onSessionAdded(org.opendaylight.openflowplugin.api.openflow.md.core.session.SwitchSessionKeyOF, org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext)}
*/
public void testOnAdded() {
SwitchSessionKeyOF switchSessionKeyOF = new SwitchSessionKeyOF();
salRegistrationManager.onSessionAdded(switchSessionKeyOF, context);
}
-
-
- private class MockNotificationProviderService implements NotificationProviderService {
-
- @Override
- public void publish(Notification notification) {
-
- }
-
- @Override
- public void publish(Notification notification, ExecutorService executorService) {
-
- }
-
- @Override
- public ListenerRegistration<NotificationInterestListener> registerInterestListener(NotificationInterestListener notificationInterestListener) {
- return null;
- }
-
- @Override
- public <T extends Notification> ListenerRegistration<NotificationListener<T>> registerNotificationListener(Class<T> tClass, NotificationListener<T> tNotificationListener) {
- return null;
- }
-
- @Override
- public ListenerRegistration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener notificationListener) {
- return null;
- }
- }
-
}