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 | b3abf52 | 2022-12-19 13:20:02 +0530 | [diff] [blame] | 33 | SubscribersPath string = "/subscribers/{id}" |
| 34 | ProfilesPath string = "/profiles/{id}" |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 35 | IgmpProxyPath string = "/igmp-proxy" |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame^] | 36 | IgmpProxyDeletePath string = "/igmp-proxy/{outgoingigmpvlanid}" |
| 37 | MulticastPath string = "/multicast/" |
| 38 | MulticastDeletePath string = "/multicast/{egressvlan}" |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 39 | FlowsPath string = "/flows" |
Akash Soni | b3abf52 | 2022-12-19 13:20:02 +0530 | [diff] [blame] | 40 | DevicesPath string = "/devices" |
| 41 | PortsPath string = "/devices/ports" |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 42 | PortsPerDeviceIDPath string = "/devices/{olt_of_id}/ports" |
Akash Soni | b3abf52 | 2022-12-19 13:20:02 +0530 | [diff] [blame] | 43 | FlowsPerDeviceIDPath string = "/flows/{deviceId}" |
| 44 | FlowPerDeviceIDFlowIDPath string = "/flows/{deviceId}/{flowId}" |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 45 | PendingFlowsPath string = "/flows/pending" |
| 46 | ProgrammedSubscribersPath string = "/programmed-subscribers" |
Akash Soni | b3abf52 | 2022-12-19 13:20:02 +0530 | [diff] [blame] | 47 | ServiceDevicePortPath string = "/services/{device}/{port}" |
| 48 | ServicePortNamePath string = "/services/{portName}" |
| 49 | ServicePortStagCtagTpIDPath string = "/services/{portName}/{sTag}/{cTag}/{tpId}" |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 50 | AllocationsPath string = "/allocations" |
Akash Soni | b3abf52 | 2022-12-19 13:20:02 +0530 | [diff] [blame] | 51 | 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 Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 60 | OltFlowServicePath string = "/oltflowservice" |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame^] | 61 | NetConfigPath string = "/network/configurations" |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 62 | ) |
Akash Soni | b3abf52 | 2022-12-19 13:20:02 +0530 | [diff] [blame] | 63 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 64 | // RestStart to execute for API |
| 65 | func RestStart() { |
| 66 | mu := mux.NewRouter() |
| 67 | logger.Info(ctx, "Rest Server Starting...") |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 68 | mu.HandleFunc(SubscribersPath, (&SubscriberHandle{}).ServeHTTP) |
| 69 | mu.HandleFunc(ProfilesPath, (&ProfileHandle{}).ServeHTTP) |
| 70 | mu.HandleFunc(IgmpProxyPath, (&IgmpProxyHandle{}).ServeHTTP) |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame^] | 71 | mu.HandleFunc(IgmpProxyDeletePath, (&IgmpProxyHandle{}).ServeHTTP) |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 72 | mu.HandleFunc(MulticastPath, (&MulticastHandle{}).ServeHTTP) |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame^] | 73 | mu.HandleFunc(MulticastDeletePath, (&MulticastHandle{}).ServeHTTP) |
Akash Soni | b3abf52 | 2022-12-19 13:20:02 +0530 | [diff] [blame] | 74 | 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 Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 86 | mu.HandleFunc(PortsPerDeviceIDPath, (&onos_nbi.DevicePortHandle{}).ServeHTTPWithDeviceID) |
Akash Soni | b3abf52 | 2022-12-19 13:20:02 +0530 | [diff] [blame] | 87 | 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 Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 95 | mu.HandleFunc(OltFlowServicePath, (&onos_nbi.OltFlowServiceHandle{}).ServeHTTP) |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame^] | 96 | mu.HandleFunc(NetConfigPath, (&NetConfigHandle{}).NetConfigServeHTTP) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 97 | err := http.ListenAndServe(":8181", mu) |
| 98 | logger.Infow(ctx, "Rest Server Started", log.Fields{"Error": err}) |
| 99 | } |
| 100 | |
| 101 | func init() { |
| 102 | // Setup this package so that it's log level can be modified at run time |
| 103 | var err error |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 104 | logger, err = log.AddPackageWithDefaultParam() |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 105 | if err != nil { |
| 106 | panic(err) |
| 107 | } |
| 108 | } |