blob: dff8549f96a082072931dbfd89a0d25dac63c108 [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.
Akash Sonib3abf522022-12-19 13:20:02 +053014 */
Naveen Sampath04696f72022-06-13 15:19:14 +053015
16package nbi
17
18import (
19 "context"
20 "net/http"
21
Akash Sonib3abf522022-12-19 13:20:02 +053022 "voltha-go-controller/voltha-go-controller/onos_nbi"
23
Naveen Sampath04696f72022-06-13 15:19:14 +053024 "github.com/gorilla/mux"
25
Tinoj Joseph1d108322022-07-13 10:07:39 +053026 "voltha-go-controller/log"
Naveen Sampath04696f72022-06-13 15:19:14 +053027)
28
29var logger log.CLogger
30var ctx = context.TODO()
31
Tinoj Josephec742f62022-09-29 19:11:10 +053032const (
Akash Soni87a19072023-02-28 00:46:59 +053033 BasePath string = "/vgc/v1"
Akash Sonib3abf522022-12-19 13:20:02 +053034 SubscribersPath string = "/subscribers/{id}"
35 ProfilesPath string = "/profiles/{id}"
Tinoj Josephaf37ce82022-12-28 11:59:43 +053036 IgmpProxyPath string = "/igmp-proxy"
Akash Sonia8246972023-01-03 10:37:08 +053037 IgmpProxyDeletePath string = "/igmp-proxy/{outgoingigmpvlanid}"
38 MulticastPath string = "/multicast/"
39 MulticastDeletePath string = "/multicast/{egressvlan}"
Tinoj Josephaf37ce82022-12-28 11:59:43 +053040 FlowsPath string = "/flows"
Akash Sonib3abf522022-12-19 13:20:02 +053041 DevicesPath string = "/devices"
42 PortsPath string = "/devices/ports"
Tinoj Josephaf37ce82022-12-28 11:59:43 +053043 PortsPerDeviceIDPath string = "/devices/{olt_of_id}/ports"
Akash Sonib3abf522022-12-19 13:20:02 +053044 FlowsPerDeviceIDPath string = "/flows/{deviceId}"
45 FlowPerDeviceIDFlowIDPath string = "/flows/{deviceId}/{flowId}"
Tinoj Josephaf37ce82022-12-28 11:59:43 +053046 PendingFlowsPath string = "/flows/pending"
47 ProgrammedSubscribersPath string = "/programmed-subscribers"
Akash Sonib3abf522022-12-19 13:20:02 +053048 ServiceDevicePortPath string = "/services/{device}/{port}"
49 ServicePortNamePath string = "/services/{portName}"
50 ServicePortStagCtagTpIDPath string = "/services/{portName}/{sTag}/{cTag}/{tpId}"
Tinoj Josephaf37ce82022-12-28 11:59:43 +053051 AllocationsPath string = "/allocations"
Akash Sonib3abf522022-12-19 13:20:02 +053052 AllocationsDeviceIDPath string = "/allocations/{deviceId}"
53 MecLearnerPath string = "/mapping/all"
54 MecLearnerDeviceIdAndPortNoPath string = "/mapping/{deviceId}/{portNumber}"
55 MecLearnerDevicePortAndVlanIdPath string = "/mapping/{deviceId}/{portNumber}/{vlanId}"
56 PortIgnoredPath string = "/ports/ignored"
57 MetersParh string = "/meters"
58 MetersByIdPath string = "/meters/{id}"
59 GroupsPath string = "/groups"
60 GroupsByIdPath string = "/groups/{id}"
Tinoj Joseph4ead4e02023-01-30 03:12:44 +053061 OltFlowServicePath string = "/oltflowservice"
Akash Sonia8246972023-01-03 10:37:08 +053062 NetConfigPath string = "/network/configurations"
Akash Soni87a19072023-02-28 00:46:59 +053063 DeviceConfigPath string = "/olt/{serialNumber}"
Tinoj Josephec742f62022-09-29 19:11:10 +053064)
Akash Sonib3abf522022-12-19 13:20:02 +053065
Naveen Sampath04696f72022-06-13 15:19:14 +053066// RestStart to execute for API
67func RestStart() {
68 mu := mux.NewRouter()
69 logger.Info(ctx, "Rest Server Starting...")
Akash Soni87a19072023-02-28 00:46:59 +053070 mu.HandleFunc(BasePath+SubscribersPath, (&SubscriberHandle{}).ServeHTTP)
71 mu.HandleFunc(BasePath+ProfilesPath, (&ProfileHandle{}).ServeHTTP)
72 mu.HandleFunc(BasePath+IgmpProxyPath, (&IgmpProxyHandle{}).ServeHTTP)
73 mu.HandleFunc(BasePath+IgmpProxyDeletePath, (&IgmpProxyHandle{}).ServeHTTP)
74 mu.HandleFunc(BasePath+MulticastPath, (&MulticastHandle{}).ServeHTTP)
75 mu.HandleFunc(BasePath+MulticastDeletePath, (&MulticastHandle{}).ServeHTTP)
76 mu.HandleFunc(BasePath+FlowsPath, (&onos_nbi.FlowHandle{}).ServeHTTP)
77 mu.HandleFunc(BasePath+FlowsPerDeviceIDPath, (&onos_nbi.FlowHandle{}).ServeHTTP)
78 mu.HandleFunc(BasePath+FlowPerDeviceIDFlowIDPath, (&onos_nbi.FlowHandle{}).ServeHTTP)
79 mu.HandleFunc(BasePath+PendingFlowsPath, (&onos_nbi.PendingFlowHandle{}).ServeHTTP)
80 mu.HandleFunc(BasePath+ProgrammedSubscribersPath, (&onos_nbi.ServiceAdapter{}).ServeHTTP)
81 mu.HandleFunc(BasePath+ServiceDevicePortPath, (&onos_nbi.ServiceAdapter{}).ServeHTTP)
82 mu.HandleFunc(BasePath+ServicePortNamePath, (&onos_nbi.ServiceAdapter{}).ServeHTTPWithPortName)
83 mu.HandleFunc(BasePath+ServicePortStagCtagTpIDPath, (&onos_nbi.ServiceAdapter{}).ServeHTTPWithPortName)
84 mu.HandleFunc(BasePath+AllocationsPath, (&onos_nbi.DhcpRelayHandle{}).ServeHTTP)
85 mu.HandleFunc(BasePath+AllocationsDeviceIDPath, (&onos_nbi.DhcpRelayHandle{}).ServeHTTP)
86 mu.HandleFunc(BasePath+DevicesPath, (&onos_nbi.DeviceHandle{}).ServeHTTP)
87 mu.HandleFunc(BasePath+PortsPath, (&onos_nbi.DevicePortHandle{}).ServeHTTP)
88 mu.HandleFunc(BasePath+PortsPerDeviceIDPath, (&onos_nbi.DevicePortHandle{}).ServeHTTPWithDeviceID)
89 mu.HandleFunc(BasePath+MecLearnerPath, (&onos_nbi.MacLearnerHandle{}).ServeHTTP)
90 mu.HandleFunc(BasePath+MecLearnerDeviceIdAndPortNoPath, (&onos_nbi.MacLearnerHandle{}).ServeHTTP)
91 mu.HandleFunc(BasePath+MecLearnerDevicePortAndVlanIdPath, (&onos_nbi.MacLearnerHandle{}).ServeHTTP)
92 mu.HandleFunc(BasePath+PortIgnoredPath, (&onos_nbi.PortIgnoredHandle{}).PortsIgnoredServeHTTP)
93 mu.HandleFunc(BasePath+MetersParh, (&onos_nbi.MetersHandle{}).MeterServeHTTP)
94 mu.HandleFunc(BasePath+MetersByIdPath, (&onos_nbi.MetersHandle{}).MeterServeHTTP)
95 mu.HandleFunc(BasePath+GroupsPath, (&onos_nbi.GroupsHandle{}).GroupServeHTTP)
96 mu.HandleFunc(BasePath+GroupsByIdPath, (&onos_nbi.GroupsHandle{}).GroupServeHTTP)
97 mu.HandleFunc(BasePath+OltFlowServicePath, (&onos_nbi.OltFlowServiceHandle{}).ServeHTTP)
98 mu.HandleFunc(BasePath+NetConfigPath, (&NetConfigHandle{}).NetConfigServeHTTP)
99 mu.HandleFunc(BasePath+DeviceConfigPath, (&onos_nbi.DeviceConfigHandle{}).ServeHTTP)
100
Naveen Sampath04696f72022-06-13 15:19:14 +0530101 err := http.ListenAndServe(":8181", mu)
102 logger.Infow(ctx, "Rest Server Started", log.Fields{"Error": err})
103}
104
105func init() {
106 // Setup this package so that it's log level can be modified at run time
107 var err error
Tinoj Joseph1d108322022-07-13 10:07:39 +0530108 logger, err = log.AddPackageWithDefaultParam()
Naveen Sampath04696f72022-06-13 15:19:14 +0530109 if err != nil {
110 panic(err)
111 }
112}