blob: e8a7e50490ea85387240b802e87d0091335ab142 [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 Sonib3abf522022-12-19 13:20:02 +053033 SubscribersPath string = "/subscribers/{id}"
34 ProfilesPath string = "/profiles/{id}"
Tinoj Josephaf37ce82022-12-28 11:59:43 +053035 IgmpProxyPath string = "/igmp-proxy"
Akash Sonia8246972023-01-03 10:37:08 +053036 IgmpProxyDeletePath string = "/igmp-proxy/{outgoingigmpvlanid}"
37 MulticastPath string = "/multicast/"
38 MulticastDeletePath string = "/multicast/{egressvlan}"
Tinoj Josephaf37ce82022-12-28 11:59:43 +053039 FlowsPath string = "/flows"
Akash Sonib3abf522022-12-19 13:20:02 +053040 DevicesPath string = "/devices"
41 PortsPath string = "/devices/ports"
Tinoj Josephaf37ce82022-12-28 11:59:43 +053042 PortsPerDeviceIDPath string = "/devices/{olt_of_id}/ports"
Akash Sonib3abf522022-12-19 13:20:02 +053043 FlowsPerDeviceIDPath string = "/flows/{deviceId}"
44 FlowPerDeviceIDFlowIDPath string = "/flows/{deviceId}/{flowId}"
Tinoj Josephaf37ce82022-12-28 11:59:43 +053045 PendingFlowsPath string = "/flows/pending"
46 ProgrammedSubscribersPath string = "/programmed-subscribers"
Akash Sonib3abf522022-12-19 13:20:02 +053047 ServiceDevicePortPath string = "/services/{device}/{port}"
48 ServicePortNamePath string = "/services/{portName}"
49 ServicePortStagCtagTpIDPath string = "/services/{portName}/{sTag}/{cTag}/{tpId}"
Tinoj Josephaf37ce82022-12-28 11:59:43 +053050 AllocationsPath string = "/allocations"
Akash Sonib3abf522022-12-19 13:20:02 +053051 AllocationsDeviceIDPath string = "/allocations/{deviceId}"
52 MecLearnerPath string = "/mapping/all"
53 MecLearnerDeviceIdAndPortNoPath string = "/mapping/{deviceId}/{portNumber}"
54 MecLearnerDevicePortAndVlanIdPath string = "/mapping/{deviceId}/{portNumber}/{vlanId}"
55 PortIgnoredPath string = "/ports/ignored"
56 MetersParh string = "/meters"
57 MetersByIdPath string = "/meters/{id}"
58 GroupsPath string = "/groups"
59 GroupsByIdPath string = "/groups/{id}"
Tinoj Joseph4ead4e02023-01-30 03:12:44 +053060 OltFlowServicePath string = "/oltflowservice"
Akash Sonia8246972023-01-03 10:37:08 +053061 NetConfigPath string = "/network/configurations"
Tinoj Josephec742f62022-09-29 19:11:10 +053062)
Akash Sonib3abf522022-12-19 13:20:02 +053063
Naveen Sampath04696f72022-06-13 15:19:14 +053064// RestStart to execute for API
65func RestStart() {
66 mu := mux.NewRouter()
67 logger.Info(ctx, "Rest Server Starting...")
Tinoj Josephec742f62022-09-29 19:11:10 +053068 mu.HandleFunc(SubscribersPath, (&SubscriberHandle{}).ServeHTTP)
69 mu.HandleFunc(ProfilesPath, (&ProfileHandle{}).ServeHTTP)
70 mu.HandleFunc(IgmpProxyPath, (&IgmpProxyHandle{}).ServeHTTP)
Akash Sonia8246972023-01-03 10:37:08 +053071 mu.HandleFunc(IgmpProxyDeletePath, (&IgmpProxyHandle{}).ServeHTTP)
Tinoj Josephec742f62022-09-29 19:11:10 +053072 mu.HandleFunc(MulticastPath, (&MulticastHandle{}).ServeHTTP)
Akash Sonia8246972023-01-03 10:37:08 +053073 mu.HandleFunc(MulticastDeletePath, (&MulticastHandle{}).ServeHTTP)
Akash Sonib3abf522022-12-19 13:20:02 +053074 mu.HandleFunc(FlowsPath, (&onos_nbi.FlowHandle{}).ServeHTTP)
75 mu.HandleFunc(FlowsPerDeviceIDPath, (&onos_nbi.FlowHandle{}).ServeHTTP)
76 mu.HandleFunc(FlowPerDeviceIDFlowIDPath, (&onos_nbi.FlowHandle{}).ServeHTTP)
77 mu.HandleFunc(PendingFlowsPath, (&onos_nbi.PendingFlowHandle{}).ServeHTTP)
78 mu.HandleFunc(ProgrammedSubscribersPath, (&onos_nbi.ServiceAdapter{}).ServeHTTP)
79 mu.HandleFunc(ServiceDevicePortPath, (&onos_nbi.ServiceAdapter{}).ServeHTTP)
80 mu.HandleFunc(ServicePortNamePath, (&onos_nbi.ServiceAdapter{}).ServeHTTPWithPortName)
81 mu.HandleFunc(ServicePortStagCtagTpIDPath, (&onos_nbi.ServiceAdapter{}).ServeHTTPWithPortName)
82 mu.HandleFunc(AllocationsPath, (&onos_nbi.DhcpRelayHandle{}).ServeHTTP)
83 mu.HandleFunc(AllocationsDeviceIDPath, (&onos_nbi.DhcpRelayHandle{}).ServeHTTP)
84 mu.HandleFunc(DevicesPath, (&onos_nbi.DeviceHandle{}).ServeHTTP)
85 mu.HandleFunc(PortsPath, (&onos_nbi.DevicePortHandle{}).ServeHTTP)
Tinoj Josephaf37ce82022-12-28 11:59:43 +053086 mu.HandleFunc(PortsPerDeviceIDPath, (&onos_nbi.DevicePortHandle{}).ServeHTTPWithDeviceID)
Akash Sonib3abf522022-12-19 13:20:02 +053087 mu.HandleFunc(MecLearnerPath, (&onos_nbi.MacLearnerHandle{}).ServeHTTP)
88 mu.HandleFunc(MecLearnerDeviceIdAndPortNoPath, (&onos_nbi.MacLearnerHandle{}).ServeHTTP)
89 mu.HandleFunc(MecLearnerDevicePortAndVlanIdPath, (&onos_nbi.MacLearnerHandle{}).ServeHTTP)
90 mu.HandleFunc(PortIgnoredPath, (&onos_nbi.PortIgnoredHandle{}).PortsIgnoredServeHTTP)
91 mu.HandleFunc(MetersParh, (&onos_nbi.MetersHandle{}).MeterServeHTTP)
92 mu.HandleFunc(MetersByIdPath, (&onos_nbi.MetersHandle{}).MeterServeHTTP)
93 mu.HandleFunc(GroupsPath, (&onos_nbi.GroupsHandle{}).GroupServeHTTP)
94 mu.HandleFunc(GroupsByIdPath, (&onos_nbi.GroupsHandle{}).GroupServeHTTP)
Tinoj Joseph4ead4e02023-01-30 03:12:44 +053095 mu.HandleFunc(OltFlowServicePath, (&onos_nbi.OltFlowServiceHandle{}).ServeHTTP)
Akash Sonia8246972023-01-03 10:37:08 +053096 mu.HandleFunc(NetConfigPath, (&NetConfigHandle{}).NetConfigServeHTTP)
Naveen Sampath04696f72022-06-13 15:19:14 +053097 err := http.ListenAndServe(":8181", mu)
98 logger.Infow(ctx, "Rest Server Started", log.Fields{"Error": err})
99}
100
101func init() {
102 // Setup this package so that it's log level can be modified at run time
103 var err error
Tinoj Joseph1d108322022-07-13 10:07:39 +0530104 logger, err = log.AddPackageWithDefaultParam()
Naveen Sampath04696f72022-06-13 15:19:14 +0530105 if err != nil {
106 panic(err)
107 }
108}