The provider module for the Arris designed APIs.
[packetcable.git] / packetcable-policy-server / src / test / java / org / opendaylight / controller / packetcable / provider / PCMMServiceTest.java
1 package org.opendaylight.controller.packetcable.provider;
2
3 import org.junit.After;
4 import org.junit.Assert;
5 import org.junit.Before;
6 import org.junit.Test;
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;
22
23 import java.net.InetAddress;
24
25 /**
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
28  * PacketcableProvider
29  */
30 public class PCMMServiceTest {
31
32     private Ccaps ccap;
33     private CMTS icmts;
34
35     @Before
36     public void setup() {
37         icmts = new CMTS();
38         icmts.startServer();
39
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);
50
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");
54
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");
57
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);
63     }
64
65     @After
66     public void tearDown() {
67         if (icmts != null) icmts.stopServer();
68     }
69
70     @Test
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());
76
77         // TODO - remove this sleep
78 /*
79         try {
80             Thread.sleep(100000);
81         } catch (InterruptedException e) {
82             e.printStackTrace();
83         }
84 */
85     }
86
87 //    @Test
88     public void testAddGate() throws Exception {
89         final PCMMService service = new PCMMService(IPCMMClient.CLIENT_TYPE, ccap);
90         service.addCcap();
91         final byte[] addr = new byte[4];
92         addr[0] = 10;
93         addr[1] = 32;
94         addr[2] = 110;
95         addr[3] = (byte)180;
96
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);
108
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);
114
115         // TODO - remove this sleep
116         Thread.sleep(1000);
117
118         final String msg = service.sendGateSet("app1/10.32.110.180/gate2", InetAddress.getByAddress(addr), gate,
119                 ServiceFlowDirection.Us);
120         Assert.fail(msg);
121     }
122
123 }