blob: 6c8f27d9c868efe6cf89bc993a642cf74f08d837 [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.
14*/
15
16package nbi
17
18import (
19 "bytes"
20 "encoding/json"
21 "net/http"
22 "strings"
23 "strconv"
24
25 app "voltha-go-controller/internal/pkg/application"
26 "voltha-go-controller/internal/pkg/of"
Tinoj Joseph1d108322022-07-13 10:07:39 +053027 "voltha-go-controller/log"
Naveen Sampath04696f72022-06-13 15:19:14 +053028)
29
30// IgmpProxy - configurations
31type IgmpProxy struct {
32 FastLeave string `json:"fastleave"`
33 LastQueryInterval int `json:"lastqueryinterval"`
34 MaxResp int `json:"maxresp"`
35 EnableIgmpProvisioning string `json:"enableigmpprovisioning"`
36 GlobalConnectPointMode string `json:"globalconnectpointmode"`
37 GlobalConnectPoint string `json:"globalconnectpoint"`
38 SourceDeviceAndPort string `json:"sourcedeviceandport"`
39 OutgoingIgmpVlanID int `json:"outgoingigmpvlanid"`
40 OutgoingIgmpInnerVlanID int `json:"outgoingigmpinnervlanid"`
41 OutgoingIgmpWithV3 string `json:"outgoingigmpwithv3"`
42 IgmpCos int `json:"igmpcos"`
43 IgmpUniCos int `json:"igmpunicos"`
44 PeriodicQuery string `json:"periodicquery"`
45 KeepAliveInterval int `json:"keepaliveinterval"`
46 KeepAliveCount int `json:"keepalivecount"`
47 RequestDsIgmpPackets bool `json:"requestdsigmppackets"`
48}
49
50// IgmpProxyHandle struct
51type IgmpProxyHandle struct {
52}
53
54// ServeHTTP to serve http request
55func (iph *IgmpProxyHandle) ServeHTTP(w http.ResponseWriter, r *http.Request) {
56 logger.Infow(ctx, "Received-northbound-request", log.Fields{"Method": r.Method, "URL": r.URL})
57 switch r.Method {
58 case "POST":
59 iph.AddIgmpProxyInfo(w, r)
60 case "DELETE":
61 iph.DelIgmpProxyInfo(w, r)
62 default:
63 logger.Warnw(ctx, "Unsupported Method", log.Fields{"Method": r.Method})
64 }
65}
66
67// AddIgmpProxyInfo to add igmp proxy info
68func (iph *IgmpProxyHandle) AddIgmpProxyInfo(w http.ResponseWriter, r *http.Request) {
69
70 // Get the payload to process the request
71 d := new(bytes.Buffer)
72 if _, err := d.ReadFrom(r.Body); err != nil {
73 logger.Warnw(ctx, "Error reading buffer", log.Fields{"Reason": err.Error()})
74 return
75 }
76
77 // Unmarshal the request into service configuration structure
78 req := &IgmpProxy{}
79 if err := json.Unmarshal(d.Bytes(), req); err != nil {
80 logger.Warnw(ctx, "Unmarshal Failed", log.Fields{"Reason": err.Error()})
81 http.Error(w, err.Error(), http.StatusConflict)
82 return
83 }
84 if mvp := app.GetApplication().GetMvlanProfileByTag(of.VlanType(req.OutgoingIgmpVlanID)); mvp == nil {
85 logger.Errorw(ctx, "MVLAN ID not configured", log.Fields{"mvlan": req.OutgoingIgmpVlanID})
86 http.Error(w, "MVLAN profile does not exists", http.StatusConflict)
87 return
88 }
89 logger.Debugw(ctx, "Received-northbound-add-service-request", log.Fields{"req": req})
90
91 go iph.addIgmpProxy(w, req)
92}
93
94// DelIgmpProxyInfo to delete igmp proxy info
95func (iph *IgmpProxyHandle) DelIgmpProxyInfo(w http.ResponseWriter, r *http.Request) {
96
97}
98
99func (iph *IgmpProxyHandle) addIgmpProxy(w http.ResponseWriter, req *IgmpProxy) {
100 var config McastConfig
101
102 config.OltSerialNum = req.SourceDeviceAndPort
103 //config.MvlanProfileID = mvp.Name
104 //config.IgmpProfileID =
105 //config.IgmpProxyIP =
106 var splits = strings.Split(req.SourceDeviceAndPort, "/")
107 config.OltSerialNum = splits[0]
108 config.MvlanProfileID = "mvlan" + strconv.Itoa(req.OutgoingIgmpVlanID)
109
110 logger.Errorw(ctx, "IgmpProxy", log.Fields{"config":config})
111
112 if err := app.GetApplication().AddMcastConfig(config.MvlanProfileID, config.IgmpProfileID,
113 config.IgmpProxyIP, config.OltSerialNum); err != nil {
114 logger.Errorw(ctx, "northbound-add-mcast-config-failed", log.Fields{"config": config, "Error": err})
115 http.Error(w, err.Error(), http.StatusConflict)
116 return
117 }
118
119}
120