Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 16 | package nbi |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "net/http" |
| 21 | |
| 22 | "github.com/gorilla/mux" |
| 23 | |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 24 | "voltha-go-controller/log" |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 25 | "voltha-go-controller/voltha-go-controller/onos_nbi" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | var logger log.CLogger |
| 29 | var ctx = context.TODO() |
| 30 | |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 31 | const ( |
| 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 Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 47 | // RestStart to execute for API |
| 48 | func RestStart() { |
| 49 | mu := mux.NewRouter() |
| 50 | logger.Info(ctx, "Rest Server Starting...") |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 51 | 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 Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 67 | err := http.ListenAndServe(":8181", mu) |
| 68 | logger.Infow(ctx, "Rest Server Started", log.Fields{"Error": err}) |
| 69 | } |
| 70 | |
| 71 | func init() { |
| 72 | // Setup this package so that it's log level can be modified at run time |
| 73 | var err error |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 74 | logger, err = log.AddPackageWithDefaultParam() |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 75 | if err != nil { |
| 76 | panic(err) |
| 77 | } |
| 78 | } |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 79 | |