SEBA-947: Expose bbsim command line params and IP param in OLT struct
          manual rebase
          Add IP to bbsimctl get OLT
Change-Id: Id610762ba0560b1ecb83aa4b7a7ddb861f6adfb2
diff --git a/internal/bbsim/api/grpc_api_server.go b/internal/bbsim/api/grpc_api_server.go
index 7191c2e..c17c6a9 100644
--- a/internal/bbsim/api/grpc_api_server.go
+++ b/internal/bbsim/api/grpc_api_server.go
@@ -19,6 +19,7 @@
 import (
 	"context"
 	"fmt"
+	"strings"
 
 	"github.com/opencord/bbsim/api/bbsim"
 	"github.com/opencord/bbsim/internal/bbsim/alarmsim"
@@ -73,11 +74,17 @@
 		pons = append(pons, &p)
 	}
 
+	oltAddress := strings.Split(common.Options.BBSim.OpenOltAddress, ":")[0]
+	if oltAddress == "" {
+		oltAddress = getOltIP().String()
+	}
+
 	res := bbsim.Olt{
 		ID:            int32(olt.ID),
 		SerialNumber:  olt.SerialNumber,
 		OperState:     olt.OperState.Current(),
 		InternalState: olt.InternalState.Current(),
+		IP:            oltAddress,
 		NNIPorts:      nnis,
 		PONPorts:      pons,
 	}
diff --git a/internal/bbsim/devices/olt.go b/internal/bbsim/devices/olt.go
index 8a0d01e..4aafaba 100644
--- a/internal/bbsim/devices/olt.go
+++ b/internal/bbsim/devices/olt.go
@@ -1188,3 +1188,21 @@
 	o.channel <- msg
 	return nil
 }
+
+func getOltIP() net.IP {
+	conn, err := net.Dial("udp", "8.8.8.8:80")
+	if err != nil {
+		oltLogger.Error(err.Error())
+		return net.IP{}
+	}
+	defer func() {
+		err := conn.Close()
+		if err != nil {
+			oltLogger.Error(err.Error())
+		}
+	}()
+
+	localAddr := conn.LocalAddr().(*net.UDPAddr)
+
+	return localAddr.IP
+}
diff --git a/internal/bbsimctl/commands/olt.go b/internal/bbsimctl/commands/olt.go
index f1553db..3ea004c 100644
--- a/internal/bbsimctl/commands/olt.go
+++ b/internal/bbsimctl/commands/olt.go
@@ -33,7 +33,7 @@
 )
 
 const (
-	DEFAULT_OLT_DEVICE_HEADER_FORMAT = "table{{ .ID }}\t{{ .SerialNumber }}\t{{ .OperState }}\t{{ .InternalState }}"
+	DEFAULT_OLT_DEVICE_HEADER_FORMAT = "table{{ .ID }}\t{{ .SerialNumber }}\t{{ .OperState }}\t{{ .InternalState }}\t{{ .IP }}"
 	DEFAULT_PORT_HEADER_FORMAT       = "table{{ .ID }}\t{{ .OperState }}"
 )
 
diff --git a/internal/common/options.go b/internal/common/options.go
index f1f5f0a..6724d1f 100644
--- a/internal/common/options.go
+++ b/internal/common/options.go
@@ -160,6 +160,10 @@
 	pon := flag.Int("pon", int(conf.Olt.PonPorts), "Number of PON ports per OLT device to be emulated")
 	onu := flag.Int("onu", int(conf.Olt.OnusPonPort), "Number of ONU devices per PON port to be emulated")
 
+	openolt_address := flag.String("openolt_address", conf.BBSim.OpenOltAddress, "IP address:port")
+	api_address := flag.String("api_address", conf.BBSim.ApiAddress, "IP address:port")
+	rest_api_address := flag.String("rest_api_address", conf.BBSim.RestApiAddress, "IP address:port")
+
 	s_tag := flag.Int("s_tag", conf.BBSim.STag, "S-Tag initial value")
 	c_tag_init := flag.Int("c_tag", conf.BBSim.CTagInit, "C-Tag starting value, each ONU will get a sequential one (targeting 1024 ONUs per BBSim instance the range is big enough)")
 
@@ -195,6 +199,9 @@
 	conf.BBSim.EnablePerf = *enablePerf
 	conf.BBSim.Events = *enableEvents
 	conf.BBSim.KafkaAddress = *kafkaAddress
+	conf.BBSim.OpenOltAddress = *openolt_address
+	conf.BBSim.ApiAddress = *api_address
+	conf.BBSim.RestApiAddress = *rest_api_address
 
 	// update device id if not set
 	if conf.Olt.DeviceId == "" {