From 8c51ea618b7fcea16e46730c4f001d9c3b10afa1 Mon Sep 17 00:00:00 2001 From: tosinski Date: Tue, 15 Feb 2022 10:43:13 -0800 Subject: [PATCH 1/2] Make p4info and device_config paths configurable --- conf/upf.json | 4 +++- pfcpiface/config.go | 32 +++++++++++++++++++++++++++++--- pfcpiface/up4.go | 35 ++++++++++++++++------------------- pfcpiface/upf.go | 11 ----------- 4 files changed, 48 insertions(+), 34 deletions(-) diff --git a/conf/upf.json b/conf/upf.json index 3a0c65fc4..00a6ec163 100644 --- a/conf/upf.json +++ b/conf/upf.json @@ -148,6 +148,8 @@ "p4rtciface": { "access_ip": "172.17.0.1/32", "p4rtc_server": "onos", - "p4rtc_port": "51001" + "p4rtc_port": "51001", + "" : "p4info: /bin/p4info.txt", + "" : "device_config: /bin/bmv2.json" } } diff --git a/pfcpiface/config.go b/pfcpiface/config.go index 3013b00de..aff9e61ea 100644 --- a/pfcpiface/config.go +++ b/pfcpiface/config.go @@ -14,6 +14,16 @@ import ( "os" ) +const ( + // Default values + maxReqRetriesDefault = 5 + respTimeoutDefault = 2 * time.Second + hbIntervalDefault = 5 * time.Second + readTimeoutDefault = 15 * time.Second + p4InfoPathDefault = "/bin/p4info.txt" + deviceConfigPathDefault = "/bin/bmv2.json" +) + // Conf : Json conf struct. type Conf struct { Mode string `json:"mode"` @@ -86,9 +96,11 @@ type IfaceType struct { // P4rtcInfo : P4 runtime interface settings. type P4rtcInfo struct { - AccessIP string `json:"access_ip"` - P4rtcServer string `json:"p4rtc_server"` - P4rtcPort string `json:"p4rtc_port"` + P4Info string `json:"p4info"` + DeviceConfig string `json:"device_config"` + AccessIP string `json:"access_ip"` + P4rtcServer string `json:"p4rtc_server"` + P4rtcPort string `json:"p4rtc_port"` } // validateConf checks that the given config reaches a baseline of correctness. @@ -190,6 +202,20 @@ func LoadConfigFile(filepath string) (Conf, error) { conf.MaxReqRetries = maxReqRetriesDefault } + if conf.EnableHBTimer { + if conf.HeartBeatInterval == "" { + conf.HeartBeatInterval = hbIntervalDefault.String() + } + } + + if conf.P4rtcIface.P4Info == "" { + conf.P4rtcIface.P4Info = p4InfoPathDefault + } + + if conf.P4rtcIface.DeviceConfig == "" { + conf.P4rtcIface.DeviceConfig = deviceConfigPathDefault + } + // Perform basic validation. err = validateConf(conf) if err != nil { diff --git a/pfcpiface/up4.go b/pfcpiface/up4.go index 38ff0c940..d51b01002 100644 --- a/pfcpiface/up4.go +++ b/pfcpiface/up4.go @@ -20,12 +20,6 @@ import ( "github.com/wmnsk/go-pfcp/ie" ) -const ( - // FIXME: this is hardcoded currently, but should be passed as configuration/cmd line arg - p4InfoPath = "/bin/p4info.txt" - deviceConfigPath = "/bin/bmv2.json" -) - var ( p4RtcServerIP = flag.String("p4RtcServerIP", "", "P4 Server ip") p4RtcServerPort = flag.String("p4RtcServerPort", "", "P4 Server port") @@ -54,13 +48,13 @@ type counter struct { } type UP4 struct { + conf P4rtcInfo + host string deviceID uint64 timeout uint32 accessIP *net.IPNet ueIPPool *net.IPNet - p4rtcServer string - p4rtcPort string enableEndMarker bool p4client *P4rtClient @@ -169,7 +163,7 @@ func (up4 *UP4) setupChannel() error { err = up4.p4client.GetForwardingPipelineConfig() if err != nil { - err = up4.p4client.SetForwardingPipelineConfig(p4InfoPath, deviceConfigPath) + err = up4.p4client.SetForwardingPipelineConfig(up4.conf.P4Info, up4.conf.DeviceConfig) if err != nil { log.Errorf("set forwarding pipeling config failed: %v", err) return err @@ -240,35 +234,38 @@ func (up4 *UP4) isConnected(accessIP *net.IP) bool { func (up4 *UP4) setUpfInfo(u *upf, conf *Conf) { log.Println("setUpfInfo UP4") + up4.conf = conf.P4rtcIface + up4.accessIP = MustParseStrIP(conf.P4rtcIface.AccessIP) u.accessIP = up4.accessIP.IP - log.Println("AccessIP: ", up4.accessIP) + log.Infof("AccessIP: %v", up4.accessIP) up4.ueIPPool = MustParseStrIP(conf.CPIface.UEIPPool) log.Infof("UE IP pool: %v", up4.ueIPPool) - up4.p4rtcServer = conf.P4rtcIface.P4rtcServer - log.Println("UP4 server ip/name", up4.p4rtcServer) - up4.p4rtcPort = conf.P4rtcIface.P4rtcPort + p4rtcServer := conf.P4rtcIface.P4rtcServer + + p4rtcPort := conf.P4rtcIface.P4rtcPort up4.reportNotifyChan = u.reportNotifyChan if *p4RtcServerIP != "" { - up4.p4rtcServer = *p4RtcServerIP + p4rtcServer = *p4RtcServerIP } if *p4RtcServerPort != "" { - up4.p4rtcPort = *p4RtcServerPort + p4rtcPort = *p4RtcServerPort } u.coreIP = net.ParseIP(net.IPv4zero.String()) - log.Println("onos server ip ", up4.p4rtcServer) - log.Println("onos server port ", up4.p4rtcPort) + up4.host = p4rtcServer + ":" + p4rtcPort + + log.WithFields(log.Fields{ + "UP4 endpoint": up4.host, + }).Info("UP4 endpoint configured") - up4.host = up4.p4rtcServer + ":" + up4.p4rtcPort - log.Println("server name: ", up4.host) up4.deviceID = 1 up4.timeout = 30 up4.enableEndMarker = conf.EnableEndMarker diff --git a/pfcpiface/upf.go b/pfcpiface/upf.go index 5088b18ca..66188b6b2 100644 --- a/pfcpiface/upf.go +++ b/pfcpiface/upf.go @@ -72,15 +72,6 @@ const ( n3 = 0x0 n6 = 0x1 n9 = 0x2 - - // Default values for outgoing requests - maxReqRetriesDefault = 5 - respTimeoutDefault = 2 * time.Second - - // Default value for Heart Beat Interval - hbIntervalDefault = 5 * time.Second - - readTimeoutDefault = 15 * time.Second ) func (u *upf) isConnected() bool { @@ -134,9 +125,7 @@ func NewUPF(conf *Conf, fp fastPath) *upf { peers: conf.CPIface.Peers, reportNotifyChan: make(chan uint64, 1024), maxReqRetries: conf.MaxReqRetries, - respTimeout: respTimeoutDefault, enableHBTimer: conf.EnableHBTimer, - hbInterval: hbIntervalDefault, readTimeout: time.Second * time.Duration(conf.ReadTimeout), } From 6cd6aa2a7411189ae399547f6b083cdbe127fa86 Mon Sep 17 00:00:00 2001 From: tosinski Date: Tue, 15 Feb 2022 10:48:34 -0800 Subject: [PATCH 2/2] Fix golint --- pfcpiface/up4.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pfcpiface/up4.go b/pfcpiface/up4.go index d51b01002..a4955c631 100644 --- a/pfcpiface/up4.go +++ b/pfcpiface/up4.go @@ -48,7 +48,7 @@ type counter struct { } type UP4 struct { - conf P4rtcInfo + conf P4rtcInfo host string deviceID uint64