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. |
Akash Soni | b3abf52 | 2022-12-19 13:20:02 +0530 | [diff] [blame] | 14 | */ |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 15 | |
| 16 | package nbi |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "net/http" |
| 21 | |
Akash Soni | b3abf52 | 2022-12-19 13:20:02 +0530 | [diff] [blame] | 22 | "voltha-go-controller/voltha-go-controller/onos_nbi" |
| 23 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 24 | "github.com/gorilla/mux" |
| 25 | |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 26 | "voltha-go-controller/log" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 27 | ) |
| 28 | |
| 29 | var logger log.CLogger |
| 30 | var ctx = context.TODO() |
| 31 | |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 32 | const ( |
Akash Soni | 87a1907 | 2023-02-28 00:46:59 +0530 | [diff] [blame] | 33 | BasePath string = "/vgc/v1" |
Akash Soni | b3abf52 | 2022-12-19 13:20:02 +0530 | [diff] [blame] | 34 | SubscribersPath string = "/subscribers/{id}" |
| 35 | ProfilesPath string = "/profiles/{id}" |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 36 | IgmpProxyPath string = "/igmp-proxy" |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 37 | IgmpProxyDeletePath string = "/igmp-proxy/{outgoingigmpvlanid}" |
| 38 | MulticastPath string = "/multicast/" |
| 39 | MulticastDeletePath string = "/multicast/{egressvlan}" |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 40 | FlowsPath string = "/flows" |
Akash Soni | b3abf52 | 2022-12-19 13:20:02 +0530 | [diff] [blame] | 41 | DevicesPath string = "/devices" |
| 42 | PortsPath string = "/devices/ports" |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 43 | PortsPerDeviceIDPath string = "/devices/{olt_of_id}/ports" |
Akash Soni | b3abf52 | 2022-12-19 13:20:02 +0530 | [diff] [blame] | 44 | FlowsPerDeviceIDPath string = "/flows/{deviceId}" |
| 45 | FlowPerDeviceIDFlowIDPath string = "/flows/{deviceId}/{flowId}" |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 46 | PendingFlowsPath string = "/flows/pending" |
| 47 | ProgrammedSubscribersPath string = "/programmed-subscribers" |
Akash Soni | b3abf52 | 2022-12-19 13:20:02 +0530 | [diff] [blame] | 48 | ServiceDevicePortPath string = "/services/{device}/{port}" |
| 49 | ServicePortNamePath string = "/services/{portName}" |
| 50 | ServicePortStagCtagTpIDPath string = "/services/{portName}/{sTag}/{cTag}/{tpId}" |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 51 | AllocationsPath string = "/allocations" |
Akash Soni | b3abf52 | 2022-12-19 13:20:02 +0530 | [diff] [blame] | 52 | 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 Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 61 | OltFlowServicePath string = "/oltflowservice" |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 62 | NetConfigPath string = "/network/configurations" |
Akash Soni | 87a1907 | 2023-02-28 00:46:59 +0530 | [diff] [blame] | 63 | DeviceConfigPath string = "/olt/{serialNumber}" |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 64 | ) |
Akash Soni | b3abf52 | 2022-12-19 13:20:02 +0530 | [diff] [blame] | 65 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 66 | // RestStart to execute for API |
| 67 | func RestStart() { |
| 68 | mu := mux.NewRouter() |
| 69 | logger.Info(ctx, "Rest Server Starting...") |
Akash Soni | 87a1907 | 2023-02-28 00:46:59 +0530 | [diff] [blame] | 70 | 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 Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 101 | err := http.ListenAndServe(":8181", mu) |
| 102 | logger.Infow(ctx, "Rest Server Started", log.Fields{"Error": err}) |
| 103 | } |
| 104 | |
| 105 | func init() { |
| 106 | // Setup this package so that it's log level can be modified at run time |
| 107 | var err error |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 108 | logger, err = log.AddPackageWithDefaultParam() |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 109 | if err != nil { |
| 110 | panic(err) |
| 111 | } |
| 112 | } |