1 package org.opendaylight.controller.packetcable.provider;
3 import org.junit.After;
4 import org.junit.Assert;
5 import org.junit.Before;
7 import org.mockito.Mockito;
8 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
9 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
10 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
11 import org.opendaylight.yang.gen.v1.urn.packetcable.rev150327.ServiceClassName;
12 import org.opendaylight.yang.gen.v1.urn.packetcable.rev150327.ServiceFlowDirection;
13 import org.opendaylight.yang.gen.v1.urn.packetcable.rev150327.ccap.Ccaps;
14 import org.opendaylight.yang.gen.v1.urn.packetcable.rev150327.ccap.attributes.AmId;
15 import org.opendaylight.yang.gen.v1.urn.packetcable.rev150327.ccap.attributes.Connection;
16 import org.opendaylight.yang.gen.v1.urn.packetcable.rev150327.pcmm.qos.classifier.Classifier;
17 import org.opendaylight.yang.gen.v1.urn.packetcable.rev150327.pcmm.qos.gate.spec.GateSpec;
18 import org.opendaylight.yang.gen.v1.urn.packetcable.rev150327.pcmm.qos.gates.apps.subs.Gates;
19 import org.opendaylight.yang.gen.v1.urn.packetcable.rev150327.pcmm.qos.traffic.profile.TrafficProfile;
20 import org.pcmm.rcd.IPCMMClient;
21 import org.pcmm.rcd.impl.CMTS;
23 import java.net.InetAddress;
26 * Tests the PCMMService's ability to connect to a CMTS. Gate additions will not properly work as there is currently
27 * not any other means to receive acknowledgements. This functionality must be tested by the PCMMService's client
30 public class PCMMServiceTest {
40 ccap = Mockito.mock(Ccaps.class);
41 final Connection conn = Mockito.mock(Connection.class);
42 Mockito.when(ccap.getConnection()).thenReturn(conn);
43 final PortNumber port = Mockito.mock(PortNumber.class);
44 Mockito.when(conn.getPort()).thenReturn(port);
45 Mockito.when(port.getValue()).thenReturn(icmts.getPort());
46 final IpAddress addr = Mockito.mock(IpAddress.class);
47 Mockito.when(conn.getIpAddress()).thenReturn(addr);
48 final Ipv4Address ipv4 = Mockito.mock(Ipv4Address.class);
49 Mockito.when(addr.getIpv4Address()).thenReturn(ipv4);
51 // Switch the value to a real CMTS here to test against it
52 // Ensure the code is checked in with 127.0.0.1
53 Mockito.when(ipv4.getValue()).thenReturn("127.0.0.1");
55 // Following line has been commented out for testing against a real Arris CMTS in the Louisville development lab
56 // Mockito.when(ipv4.getValue()).thenReturn("10.32.10.3");
58 Mockito.when(ccap.getCcapId()).thenReturn("ccap-1");
59 final AmId amid = Mockito.mock(AmId.class);
60 Mockito.when(ccap.getAmId()).thenReturn(amid);
61 Mockito.when(amid.getAmTag()).thenReturn(0xcada);
62 Mockito.when(amid.getAmType()).thenReturn(1);
66 public void tearDown() {
67 if (icmts != null) icmts.stopServer();
71 public void testAddCcap() {
72 final PCMMService service = new PCMMService(IPCMMClient.CLIENT_TYPE, ccap);
73 final String message = service.addCcap();
74 Assert.assertTrue(message.startsWith("200"));
75 Assert.assertNotNull(service.ccapClient.pcmmPdp.getClientHandle());
77 // TODO - remove this sleep
81 } catch (InterruptedException e) {
88 public void testAddGate() throws Exception {
89 final PCMMService service = new PCMMService(IPCMMClient.CLIENT_TYPE, ccap);
91 final byte[] addr = new byte[4];
97 final Gates gate = Mockito.mock(Gates.class);
98 final GateSpec gateSpec = Mockito.mock(GateSpec.class);
99 Mockito.when(gate.getGateSpec()).thenReturn(gateSpec);
100 Mockito.when(gateSpec.getDirection()).thenReturn(ServiceFlowDirection.Us);
101 // TODO - make sure to write a test when this value is not null
102 Mockito.when(gateSpec.getDscpTosOverwrite()).thenReturn(null);
103 final TrafficProfile trafficProfile = Mockito.mock(TrafficProfile.class);
104 final ServiceClassName scn = Mockito.mock(ServiceClassName.class);
105 Mockito.when(scn.getValue()).thenReturn("extrm_up");
106 Mockito.when(trafficProfile.getServiceClassName()).thenReturn(scn);
107 Mockito.when(gate.getTrafficProfile()).thenReturn(trafficProfile);
109 // TODO - write tests when this is null and ExtClassifier or Ipv6Classifier objects are not null
110 final Classifier classifier = Mockito.mock(Classifier.class);
111 Mockito.when(gate.getClassifier()).thenReturn(classifier);
112 Mockito.when(gate.getExtClassifier()).thenReturn(null);
113 Mockito.when(gate.getIpv6Classifier()).thenReturn(null);
115 // TODO - remove this sleep
118 final String msg = service.sendGateSet("app1/10.32.110.180/gate2", InetAddress.getByAddress(addr), gate,
119 ServiceFlowDirection.Us);