aboutsummaryrefslogtreecommitdiffstats
path: root/svc/svcmgr/src/main/java/com/cablelabs/vcpe/svc/svcmgr/EplService.java
blob: f2c534331265eb12a3ba708c38a21d0915ecebb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*******************************************************************************
* Copyright (c) 2015 CableLabs Inc. and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution, and is available at
* http://www.apache.org/licenses/LICENSE-2.0
*******************************************************************************/

package com.cablelabs.vcpe.svc.svcmgr;


import com.cablelabs.vcpe.common.Dbg;
import com.cablelabs.vcpe.evc.evcbase.client.EvcClient;
import com.cablelabs.vcpe.svc.svcbase.model.Epl;
import com.cablelabs.vcpe.svc.svcbase.repository.EplRespositoryInMem;
import com.cablelabs.vcpe.evc.evcbase.model.Evc;


import javax.ws.rs.*;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;

/**
 * Root resource (exposed at "svc/epl" path)
 */

@Path("svc/epl")
public class EplService {

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
  //--------------------------------------------------------
    public Response create(Epl epl)
  //--------------------------------------------------------
    {
        if ( epl == null) {
            return Response.status(Response.Status.BAD_REQUEST).build();
        }

        Dbg.p("\nADDING [" + epl.getId() + "] to epl repo");

        //
        // Create an EVC
        //

        Evc evcForEpl   = new Evc();

        // Uni IDs set at lower layers
        List<String> uniIdList = new ArrayList<String>();
        uniIdList.add("unset");
        uniIdList.add("unset");

        // Transfer EPLs mac list to EVC
        List<String> uniMacList = new ArrayList<String>();
        if (epl.getUniHostMacList() != null && epl.getUniHostMacList().size() == 2) {
            uniMacList.add(epl.getUniHostMacList().get(0) );
            uniMacList.add(epl.getUniHostMacList().get(1));
        }
        else {
            return Response.status(Response.Status.BAD_REQUEST).build();
        }

        // Transfer EPLs I{P list to EVC
        List<String> uniIpList = new ArrayList<String>();
        if (epl.getUniHostIpList() != null && epl.getUniHostIpList().size() == 2) {
            uniIpList.add(epl.getUniHostIpList().get(0) );
            uniIpList.add(epl.getUniHostIpList().get(1));
        }
        else {
            return Response.status(Response.Status.BAD_REQUEST).build();
        }

        // evc mgr will set perf props based on CoS.  We need to set everything else
        evcForEpl.setAllNonPerfProps(   "unset",                          // set by lower layer (id)
                                        Evc.EvcType.POINT_TO_POINT,       // required for EPL (evcType)
                                        2,                                // required for EPL (maxUnis)
                                        uniIdList,                        // created above
                                        uniMacList, uniIpList,            // passed in
                                        Evc.FrameDelivery.UNCONDITIONAL,  // required for EPL (unicastFrameDelivery)
                                        Evc.FrameDelivery.UNCONDITIONAL,  // required for EPL (multicastFrameDelivery)
                                        Evc.FrameDelivery.UNCONDITIONAL,  // required for EPL (broadcastFrameDelivery)
                                        true,                             // required for EPL (ceVLanIdPreservation)
                                        true,                             // required for EPL (ceVlanCosPreservation)
                                        1600,                             // hard coded, need to figure out source !!
                                        epl.getCos());

        // send create request to EVC mgr
        EvcClient evcClient = new EvcClient();
        evcForEpl= evcClient.create(evcForEpl);

        // EVC Layer generates the ID, we need to capture it
        epl.setEvcId(evcForEpl.getId());

        // Now add the EPL to our local repo
        EplRespositoryInMem.INSTANCE.add(epl);
        EplRespositoryInMem.INSTANCE.dump(0);
        return Response.ok().entity(epl).build();
    }

    @PUT
    @Path("{eplId}")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
  //--------------------------------------------------------
    public Response update(Epl epl)
  //--------------------------------------------------------
    {
        Dbg.p("\nUPDATING [" + epl.getId()+"]");

        EplRespositoryInMem.INSTANCE.update(epl);
        EplRespositoryInMem.INSTANCE.dump(0);
        return Response.ok().entity(epl).build();
    }

    @GET
    @Path("{eplId}")
    @Produces(MediaType.APPLICATION_JSON)
  //--------------------------------------------------------
    public Response get( @PathParam("eplId") String eplId )
  //--------------------------------------------------------
    {
        if ( eplId == null) {
            return Response.status(Response.Status.BAD_REQUEST).build();
        }
        Dbg.p("\nRETRIEVING ["+eplId+"]");
        Epl epl = EplRespositoryInMem.INSTANCE.get(eplId);
        if (epl == null) {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
        epl.dump(1);
        return Response.ok().entity(epl).build();
    }

    @GET
    @Path("list")
    @Produces(MediaType.APPLICATION_JSON)
  //--------------------------------------------------------
    public Response eplList()
  //--------------------------------------------------------

    // get a list of all Epl objects
    {
        Dbg.p("\nEPL GET ALL:");
        List eplList = EplRespositoryInMem.INSTANCE.getAll();
        if (eplList == null  )
        {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
        return Response.ok().entity(new GenericEntity<List<Epl>>(eplList) {}).build();
    }

    @DELETE
    @Path("{eplId}")
  //--------------------------------------------------------
    public Response delete(@PathParam("eplId") String eplId)
  //--------------------------------------------------------
    {
        if ( eplId == null) {
            return Response.status(Response.Status.BAD_REQUEST).build();
        }

        // grab the full EPL so that we can get EVC ID to delete
        Epl epl = EplRespositoryInMem.INSTANCE.get(eplId);
        if (epl == null) {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
        String evcId = epl.getEvcId();

        // Delete the EVC associated with the EPL being deleted
        EvcClient evcClient = new EvcClient();
        evcClient.delete(evcId);

        Dbg.p("\nDELETE:" + eplId);
        EplRespositoryInMem.INSTANCE.delete(eplId);
        EplRespositoryInMem.INSTANCE.dump(0);
        return Response.ok().build();
    }

    @GET
    @Produces(MediaType.APPLICATION_JSON)
  //--------------------------------------------------------
    public Epl testGet()
  //--------------------------------------------------------
  // simple get to check out json format

    {
        long numLocations = 2;

        List<String> locList = new ArrayList<String>();
        locList.add("1111 MEF Dr, Honolulu HI, USA");
        locList.add("2222 MEF Dr, Boston MA, MAS");

        List<String> uniList = new ArrayList<String>();
        uniList.add("00:0a:95:9d:68:16");
        uniList.add("00:A0:C9:14:C8:29");

        List<String> ipList = new ArrayList<String>();
        ipList.add("192.168.1.10");
        ipList.add("192.168.1.10");

        Epl epl = new Epl();
        epl.setAllProps("epl-1", numLocations, locList, uniList, ipList, "gold", "unset");
        return epl;
    }

    @GET
    @Produces(MediaType.TEXT_PLAIN)
  //--------------------------------------------------------
    public String ping()
  //--------------------------------------------------------
  // simple ping to check connectivity

    {
        Dbg.p("In Epl Service: ping test");
        return "... pingEpl reponse";
    }
}