[VOL-4146] Supporting MEF and IETF format in sadis config

Change-Id: I41672c654a9be04e7abaa5aced6f06726dbd0cc3
diff --git a/VERSION b/VERSION
index 9c6d629..bd8bf88 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.6.1
+1.7.0
diff --git a/configs/bbsim.yaml b/configs/bbsim.yaml
index 6265e5c..6fb4676 100644
--- a/configs/bbsim.yaml
+++ b/configs/bbsim.yaml
@@ -24,6 +24,7 @@
   # log_caller: false
   # delay: 200
   # kafka_event_topic: ""
+  bp_format: "mef"
 
 # OLT device settings
 olt:
diff --git a/internal/bbsim/responders/sadis/dp.txt b/internal/bbsim/responders/sadis/dp.txt
new file mode 100644
index 0000000..e75501e
--- /dev/null
+++ b/internal/bbsim/responders/sadis/dp.txt
@@ -0,0 +1,44 @@
+"bandwidthprofile":{
+          "integration":{
+              "cache":{
+                  "enabled":true,
+                  "maxsize":40,
+                  "ttl":"PT1m"
+              }
+          },
+          "entries":[
+              {
+                  "id": "Default",
+                  "gir": 0,
+                  "cbs": 30,
+                  "cir": 16000,
+                  "pbs": 30,
+                  "pir": 32000
+              },
+              {
+                  "id": "User_Bandwidth1",
+                  "gir": 100000,
+                  "cbs": 10000,
+                  "cir": 30000,
+                  "pbs": 1000,
+                  "pir": 20000
+              },
+              {
+                  "id": "User_Bandwidth2",
+                  "gir": 100000,
+                  "cbs": 5000,
+                  "cir": 100000,
+                  "pbs": 5000,
+                  "pir": 300000
+              },
+              {
+                  "id": "User_Bandwidth3",
+                  "gir": 100000,
+                  "cbs": 5000,
+                  "cir": 100000,
+                  "pbs": 5000,
+                  "pir": 400000
+              }
+
+          ]
+      }
\ No newline at end of file
diff --git a/internal/bbsim/responders/sadis/sadis.go b/internal/bbsim/responders/sadis/sadis.go
index 4b9ccb3..394c9eb 100644
--- a/internal/bbsim/responders/sadis/sadis.go
+++ b/internal/bbsim/responders/sadis/sadis.go
@@ -36,11 +36,19 @@
 }
 
 // bandwidthProfiles contains some dummy profiles
-var bandwidthProfiles = []*SadisBWPEntry{
-	{ID: "User_Bandwidth1", AIR: 100000, CBS: 10000, CIR: 30000, EBS: 1000, EIR: 100000},
-	{ID: "User_Bandwidth2", AIR: 100000, CBS: 5000, CIR: 100000, EBS: 5000, EIR: 100000},
-	{ID: "User_Bandwidth3", AIR: 100000, CBS: 5000, CIR: 1000000, EBS: 5000, EIR: 1000000},
-	{ID: "Default", AIR: 100000, CBS: 30, CIR: 600, EBS: 30, EIR: 400},
+var bandwidthProfiles = map[string][]*SadisBWPEntry{
+	common.BP_FORMAT_MEF: {
+		{ID: "User_Bandwidth1", AIR: 100000, CBS: 10000, CIR: 30000, EBS: 1000, EIR: 100000},
+		{ID: "User_Bandwidth2", AIR: 100000, CBS: 5000, CIR: 100000, EBS: 5000, EIR: 100000},
+		{ID: "User_Bandwidth3", AIR: 100000, CBS: 5000, CIR: 1000000, EBS: 5000, EIR: 1000000},
+		{ID: "Default", AIR: 100000, CBS: 30, CIR: 600, EBS: 30, EIR: 400},
+	},
+	common.BP_FORMAT_IETF: {
+		{ID: "User_Bandwidth1", CBS: 10000, CIR: 30000, GIR: 100000, PIR: 20000, PBS: 1000},
+		{ID: "User_Bandwidth2", CBS: 5000, CIR: 100000, GIR: 100000, PIR: 30000, PBS: 5000},
+		{ID: "User_Bandwidth3", CBS: 5000, CIR: 1000000, GIR: 100000, PIR: 40000, PBS: 5000},
+		{ID: "Default", CBS: 30, CIR: 600, GIR: 0, PIR: 32000, PBS: 30},
+	},
 }
 
 // SadisConfig is the top-level SADIS configuration struct
@@ -102,12 +110,18 @@
 
 // SADIS BandwithProfile Entry
 type SadisBWPEntry struct {
+	// common attributes
 	ID  string `json:"id"`
-	AIR int    `json:"air"`
 	CBS int    `json:"cbs"`
 	CIR int    `json:"cir"`
-	EBS int    `json:"ebs"`
-	EIR int    `json:"eir"`
+	// MEF attributes
+	AIR int `json:"air,omitempty"`
+	EBS int `json:"ebs,omitempty"`
+	EIR int `json:"eir,omitempty"`
+	// IETF attributes
+	GIR int `json:"gir,omitempty"`
+	PIR int `json:"pir,omitempty"`
+	PBS int `json:"pbs,omitempty"`
 }
 
 // GetSadisConfig returns a full SADIS configuration struct ready to be marshalled into JSON
@@ -263,7 +277,7 @@
 	}
 
 	sadisConf.BandwidthProfile.Integration.URL = ""
-	sadisConf.BandwidthProfile.Entries = bandwidthProfiles
+	sadisConf.BandwidthProfile.Entries = bandwidthProfiles[common.Config.BBSim.BandwidthProfileFormat]
 
 	sadisJSON, _ := json.Marshal(sadisConf)
 	sadisLogger.Tracef("SADIS JSON: %s", sadisJSON)
@@ -340,7 +354,7 @@
 
 	sadisLogger.Debugf("Received request for SADIS bandwidth profile %s", id)
 
-	for _, bwpEntry := range bandwidthProfiles {
+	for _, bwpEntry := range bandwidthProfiles[common.Config.BBSim.BandwidthProfileFormat] {
 		if bwpEntry.ID == id {
 			w.WriteHeader(http.StatusOK)
 			_ = json.NewEncoder(w).Encode(bwpEntry)
diff --git a/internal/common/options.go b/internal/common/options.go
index a8010be..6dd7231 100644
--- a/internal/common/options.go
+++ b/internal/common/options.go
@@ -34,6 +34,11 @@
 	"unique",
 }
 
+const (
+	BP_FORMAT_MEF  = "mef"
+	BP_FORMAT_IETF = "ietf"
+)
+
 type TagAllocation int
 
 func (t TagAllocation) String() string {
@@ -90,27 +95,28 @@
 }
 
 type BBSimConfig struct {
-	ConfigFile           string
-	ServiceConfigFile    string
-	DhcpRetry            bool    `yaml:"dhcp_retry"`
-	AuthRetry            bool    `yaml:"auth_retry"`
-	LogLevel             string  `yaml:"log_level"`
-	LogCaller            bool    `yaml:"log_caller"`
-	Delay                int     `yaml:"delay"`
-	CpuProfile           *string `yaml:"cpu_profile"`
-	OpenOltAddress       string  `yaml:"openolt_address"`
-	ApiAddress           string  `yaml:"api_address"`
-	RestApiAddress       string  `yaml:"rest_api_address"`
-	LegacyApiAddress     string  `yaml:"legacy_api_address"`
-	LegacyRestApiAddress string  `yaml:"legacy_rest_api_address"`
-	SadisRestAddress     string  `yaml:"sadis_rest_address"`
-	SadisServer          bool    `yaml:"sadis_server"`
-	KafkaAddress         string  `yaml:"kafka_address"`
-	Events               bool    `yaml:"enable_events"`
-	ControlledActivation string  `yaml:"controlled_activation"`
-	EnablePerf           bool    `yaml:"enable_perf"`
-	KafkaEventTopic      string  `yaml:"kafka_event_topic"`
-	DmiServerAddress     string  `yaml:"dmi_server_address"`
+	ConfigFile             string
+	ServiceConfigFile      string
+	DhcpRetry              bool    `yaml:"dhcp_retry"`
+	AuthRetry              bool    `yaml:"auth_retry"`
+	LogLevel               string  `yaml:"log_level"`
+	LogCaller              bool    `yaml:"log_caller"`
+	Delay                  int     `yaml:"delay"`
+	CpuProfile             *string `yaml:"cpu_profile"`
+	OpenOltAddress         string  `yaml:"openolt_address"`
+	ApiAddress             string  `yaml:"api_address"`
+	RestApiAddress         string  `yaml:"rest_api_address"`
+	LegacyApiAddress       string  `yaml:"legacy_api_address"`
+	LegacyRestApiAddress   string  `yaml:"legacy_rest_api_address"`
+	SadisRestAddress       string  `yaml:"sadis_rest_address"`
+	SadisServer            bool    `yaml:"sadis_server"`
+	KafkaAddress           string  `yaml:"kafka_address"`
+	Events                 bool    `yaml:"enable_events"`
+	ControlledActivation   string  `yaml:"controlled_activation"`
+	EnablePerf             bool    `yaml:"enable_perf"`
+	KafkaEventTopic        string  `yaml:"kafka_event_topic"`
+	DmiServerAddress       string  `yaml:"dmi_server_address"`
+	BandwidthProfileFormat string  `yaml:"bp_format"`
 }
 
 type BBRConfig struct {
@@ -218,6 +224,7 @@
 
 	configFile := flag.String("config", conf.BBSim.ConfigFile, "Configuration file path")
 	servicesFile := flag.String("services", conf.BBSim.ServiceConfigFile, "Service Configuration file path")
+	sadisBpFormat := flag.String("bp_format", conf.BBSim.BandwidthProfileFormat, "Bandwidth profile format, 'mef' or 'ietf'")
 
 	olt_id := flag.Int("olt_id", conf.Olt.ID, "OLT device ID")
 	nni := flag.Int("nni", int(conf.Olt.NniPorts), "Number of NNI ports per OLT device to be emulated")
@@ -277,6 +284,12 @@
 		conf.Olt.DeviceId = net.HardwareAddr{0xA, 0xA, 0xA, 0xA, 0xA, byte(conf.Olt.ID)}.String()
 	}
 
+	// check that the BP format is valid
+	if (*sadisBpFormat != BP_FORMAT_MEF) && (*sadisBpFormat != BP_FORMAT_IETF) {
+		log.Fatalf("Invalid parameter 'bp_format', supported values are %s and %s, you provided %s", BP_FORMAT_MEF, BP_FORMAT_IETF, *sadisBpFormat)
+	}
+	conf.BBSim.BandwidthProfileFormat = *sadisBpFormat
+
 	return conf
 }
 
@@ -284,26 +297,27 @@
 
 	c := &GlobalConfig{
 		BBSimConfig{
-			ConfigFile:           "configs/bbsim.yaml",
-			ServiceConfigFile:    "configs/att-services.yaml",
-			LogLevel:             "debug",
-			LogCaller:            false,
-			Delay:                200,
-			OpenOltAddress:       ":50060",
-			ApiAddress:           ":50070",
-			RestApiAddress:       ":50071",
-			LegacyApiAddress:     ":50072",
-			LegacyRestApiAddress: ":50073",
-			SadisRestAddress:     ":50074",
-			SadisServer:          true,
-			KafkaAddress:         ":9092",
-			Events:               false,
-			ControlledActivation: "default",
-			EnablePerf:           false,
-			KafkaEventTopic:      "",
-			DhcpRetry:            false,
-			AuthRetry:            false,
-			DmiServerAddress:     ":50075",
+			ConfigFile:             "configs/bbsim.yaml",
+			ServiceConfigFile:      "configs/att-services.yaml",
+			LogLevel:               "debug",
+			LogCaller:              false,
+			Delay:                  200,
+			OpenOltAddress:         ":50060",
+			ApiAddress:             ":50070",
+			RestApiAddress:         ":50071",
+			LegacyApiAddress:       ":50072",
+			LegacyRestApiAddress:   ":50073",
+			SadisRestAddress:       ":50074",
+			SadisServer:            true,
+			KafkaAddress:           ":9092",
+			Events:                 false,
+			ControlledActivation:   "default",
+			EnablePerf:             false,
+			KafkaEventTopic:        "",
+			DhcpRetry:              false,
+			AuthRetry:              false,
+			DmiServerAddress:       ":50075",
+			BandwidthProfileFormat: BP_FORMAT_MEF,
 		},
 		OltConfig{
 			Vendor:             "BBSim",