1 package org.opendaylight.openflowplugin.impl.services;
3 import com.google.common.collect.Lists;
4 import io.netty.util.HashedWheelTimer;
5 import junit.framework.TestCase;
6 import org.junit.Before;
8 import org.junit.runner.RunWith;
9 import org.mockito.Mock;
10 import org.mockito.runners.MockitoJUnitRunner;
11 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
12 import org.opendaylight.openflowplugin.api.OFConstants;
13 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
14 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
15 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
16 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
17 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
18 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
19 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
20 import org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.Port;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.PortBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInputBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.port.update.UpdatedPort;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.port.update.UpdatedPortBuilder;
34 import java.math.BigInteger;
35 import java.util.Collections;
36 import java.util.List;
38 import static org.mockito.Mockito.mock;
39 import static org.mockito.Mockito.verify;
40 import static org.mockito.Mockito.when;
42 @RunWith(MockitoJUnitRunner.class)
43 public class SalPortServiceImplTest extends ServiceMocking {
45 private static final Long DUMMY_XID = 55L;
46 private static final Long DUMMY_PORT_NUMBER = 66L;
47 private static final String DUMMY_MAC_ADDRESS = "AA:BB:CC:DD:EE:FF";
48 SalPortServiceImpl salPortService;
51 public void initialization() {
52 super.initialization();
53 salPortService = new SalPortServiceImpl(mockedRequestContextStack, mockedDeviceContext);
57 public void testUpdatePort() throws Exception {
58 UpdatePortInput dummyUpdatePortInput = new UpdatePortInputBuilder().build();
59 salPortService.updatePort(dummyUpdatePortInput);
60 verify(mockedRequestContextStack).createRequestContext();
64 public void testBuildRequest() {
65 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.PortBuilder concretePortBuilder
66 = new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.PortBuilder();
67 concretePortBuilder.setConfiguration(new PortConfig(true, true, true, true));
68 concretePortBuilder.setAdvertisedFeatures(new PortFeatures(true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true));
69 concretePortBuilder.setPortNumber(new PortNumberUni(DUMMY_PORT_NUMBER));
70 concretePortBuilder.setHardwareAddress(new MacAddress(DUMMY_MAC_ADDRESS));
72 List<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port> ports
73 = Lists.newArrayList(concretePortBuilder.build());
74 Port port = new PortBuilder().setPort(ports).build();
75 UpdatedPort updatePort = new UpdatedPortBuilder().setPort(port).build();
76 UpdatePortInput dummyUpdatePortInput = new UpdatePortInputBuilder().setUpdatedPort(updatePort).build();
78 final OfHeader ofHeader = salPortService.buildRequest(new Xid(DUMMY_XID), dummyUpdatePortInput);