blob: ee7ad5427827da25f7bf687cd219247bd7fb7d23 [file] [log] [blame]
Matteo Scandolocedde462021-03-09 17:37:16 -08001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package webserver
18
19import (
20 "github.com/gorilla/mux"
21 "github.com/opencord/bbsim/internal/bbsim/devices"
22 "github.com/opencord/bbsim/internal/bbsim/responders/sadis"
23 "github.com/opencord/bbsim/internal/common"
24 log "github.com/sirupsen/logrus"
25 "net/http"
26 "sync"
27)
28
29var logger = log.WithFields(log.Fields{
30 "module": "WEBSERVER",
31})
32
33// StartRestServer starts REST server which esposes:
34// - a SADIS configuration for the currently simulated OLT
35// - static files for software image download
36func StartRestServer(olt *devices.OltDevice, wg *sync.WaitGroup) {
37 addr := common.Config.BBSim.SadisRestAddress
38 logger.Infof("WEBSERVER server listening on %s", addr)
39 s := &sadis.SadisServer{
40 Olt: olt,
41 }
42
43 router := mux.NewRouter().StrictSlash(true)
44
45 // sadis routes
Matteo Scandolo8a574812021-05-20 15:18:53 -070046 router.HandleFunc(sadis.BaseConfigUrl, s.ServeBaseConfig)
47 router.HandleFunc(sadis.StaticConfigUrl, s.ServeStaticConfig)
48 router.HandleFunc(sadis.SadisEntryUrl, s.ServeEntry)
49 router.HandleFunc(sadis.SadisBwUrl, s.ServeBWPEntry)
Matteo Scandolocedde462021-03-09 17:37:16 -080050
51 // Choose the folder to serve (this is the location inside the container)
52 staticDir := "/app/configs/"
53
54 // Create the route
55 router.
56 PathPrefix("/images/").
57 Handler(http.StripPrefix("/images/", http.FileServer(http.Dir(staticDir))))
58
59 log.Fatal(http.ListenAndServe(addr, router))
60
61 wg.Done()
62}