blob: e768cb44b02d849aba2b064cd6b47d7a960af08d [file] [log] [blame]
Naveen Sampath04696f72022-06-13 15:19:14 +05301/*
2* Copyright 2022-present Open Networking Foundation
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14*/
15
16package nbi
17
18import (
19 "context"
20 "net/http"
21
22 "github.com/gorilla/mux"
23
Tinoj Joseph1d108322022-07-13 10:07:39 +053024 "voltha-go-controller/log"
Tinoj Josephec742f62022-09-29 19:11:10 +053025 "voltha-go-controller/voltha-go-controller/onos_nbi"
Naveen Sampath04696f72022-06-13 15:19:14 +053026)
27
28var logger log.CLogger
29var ctx = context.TODO()
30
Tinoj Josephec742f62022-09-29 19:11:10 +053031const (
32 SubscribersPath string = "/subscribers/{id}"
33 ProfilesPath string = "/profiles/{id}"
34 IgmpProxyPath string = "/igmp-proxy/"
35 MulticastPath string = "/multicast/"
36 FlowsPath string = "/flows/"
37 FlowsPerDeviceIDPath string = "/flows/{deviceId}"
38 FlowPerDeviceIDFlowIDPath string = "/flows/{deviceId}/{flowId}"
39 PendingFlowsPath string = "/flows/pending/"
40 ProgrammedSubscribersPath string = "/programmed-subscribers/"
41 ServiceDevicePortPath string = "/services/{device}/{port}"
42 ServicePortNamePath string = "/services/{portName}"
43 ServicePortStagCtagTpIDPath string = "/services/{portName}/{sTag}/{cTag}/{tpId}"
44 AllocationsPath string = "/allocations/"
45 AllocationsDeviceIDPath string = "/allocations/{deviceId}"
46)
Naveen Sampath04696f72022-06-13 15:19:14 +053047// RestStart to execute for API
48func RestStart() {
49 mu := mux.NewRouter()
50 logger.Info(ctx, "Rest Server Starting...")
Tinoj Josephec742f62022-09-29 19:11:10 +053051 mu.HandleFunc(SubscribersPath, (&SubscriberHandle{}).ServeHTTP)
52 mu.HandleFunc(ProfilesPath, (&ProfileHandle{}).ServeHTTP)
53 mu.HandleFunc(IgmpProxyPath, (&IgmpProxyHandle{}).ServeHTTP)
54 mu.HandleFunc(MulticastPath, (&MulticastHandle{}).ServeHTTP)
55
56 mu.HandleFunc(FlowsPath, (&onos_nbi.FlowHandle{}).ServeHTTP)
57 mu.HandleFunc(FlowsPerDeviceIDPath, (&onos_nbi.FlowHandle{}).ServeHTTP)
58 mu.HandleFunc(FlowPerDeviceIDFlowIDPath, (&onos_nbi.FlowHandle{}).ServeHTTP)
59 mu.HandleFunc(PendingFlowsPath, (&onos_nbi.PendingFlowHandle{}).ServeHTTP)
60 mu.HandleFunc(ProgrammedSubscribersPath, (&onos_nbi.ServiceAdapter{}).ServeHTTP)
61 mu.HandleFunc(ServiceDevicePortPath, (&onos_nbi.ServiceAdapter{}).ServeHTTP)
62 mu.HandleFunc(ServicePortNamePath, (&onos_nbi.ServiceAdapter{}).ServeHTTPWithPortName)
63 mu.HandleFunc(ServicePortStagCtagTpIDPath, (&onos_nbi.ServiceAdapter{}).ServeHTTPWithPortName)
64 mu.HandleFunc(AllocationsPath, (&onos_nbi.DhcpRelayHandle{}).ServeHTTP)
65 mu.HandleFunc(AllocationsDeviceIDPath, (&onos_nbi.DhcpRelayHandle{}).ServeHTTP)
66
Naveen Sampath04696f72022-06-13 15:19:14 +053067 err := http.ListenAndServe(":8181", mu)
68 logger.Infow(ctx, "Rest Server Started", log.Fields{"Error": err})
69}
70
71func init() {
72 // Setup this package so that it's log level can be modified at run time
73 var err error
Tinoj Joseph1d108322022-07-13 10:07:39 +053074 logger, err = log.AddPackageWithDefaultParam()
Naveen Sampath04696f72022-06-13 15:19:14 +053075 if err != nil {
76 panic(err)
77 }
78}
Tinoj Joseph1d108322022-07-13 10:07:39 +053079