From 2537427858d37b63ca8508d050acf426815d9d67 Mon Sep 17 00:00:00 2001 From: Nupur Jain Date: Mon, 8 Jan 2024 13:29:47 -0800 Subject: [PATCH] Bug fixes for arbitration & checks for null ptr (#174) Signed-off-by: nupurjai --- deploy/es2k/infraagent-config.yaml | 4 ++++ deploy/inframanager-config.yaml | 5 +++++ example/service/tcp/iperf_tcp.yaml | 10 +++++----- example/service/udp/iperf_udp.yaml | 10 +++++----- inframanager/api_handler/api_handler.go | 2 ++ pkg/inframanager/p4/service_es2k.go | 17 +++++++++++++---- pkg/utils/common.go | 10 ++++++++++ 7 files changed, 44 insertions(+), 14 deletions(-) diff --git a/deploy/es2k/infraagent-config.yaml b/deploy/es2k/infraagent-config.yaml index 598afa6b..35a793ff 100644 --- a/deploy/es2k/infraagent-config.yaml +++ b/deploy/es2k/infraagent-config.yaml @@ -11,3 +11,7 @@ insecure: false # "Debug" (Default) # "Trace" logLevel: "Debug" +#Additional configurations for split mode +#managerAddr reflects the ACC comms interface IP Addr +#managerAddr : 10.10.0.2 +#managerPort : 50002 diff --git a/deploy/inframanager-config.yaml b/deploy/inframanager-config.yaml index 1bf7301c..1079d1f5 100644 --- a/deploy/inframanager-config.yaml +++ b/deploy/inframanager-config.yaml @@ -28,6 +28,11 @@ Infrap4dGnmiServer: # ca-cert: "/etc/pki/inframanager/client/ca.crt" conn: mtls +# Possible manager addr configs +# split mode - IP address of the ACC comms interface. +# This is where inframanager listens for +# agent connections. +# host mode - loopback ip of local host InfraManager: addr: 127.0.0.1:50002 # - arp-mac diff --git a/example/service/tcp/iperf_tcp.yaml b/example/service/tcp/iperf_tcp.yaml index f523603c..17e22cab 100644 --- a/example/service/tcp/iperf_tcp.yaml +++ b/example/service/tcp/iperf_tcp.yaml @@ -57,24 +57,24 @@ spec: apiVersion: apps/v1 kind: DaemonSet metadata: - name: iperf-client + name: iperf-client-tcp labels: - app: iperf-client + app: iperf-client-tcp spec: selector: matchLabels: - app: iperf-client + app: iperf-client-tcp template: metadata: labels: - app: iperf-client + app: iperf-client-tcp spec: tolerations: - key: node-role.kubernetes.io/master operator: Exists effect: NoSchedule containers: - - name: iperf-client + - name: iperf-client-tcp image: lroktu/iperf command: ['/bin/sh', '-c', 'sleep infinity'] terminationGracePeriodSeconds: 0 diff --git a/example/service/udp/iperf_udp.yaml b/example/service/udp/iperf_udp.yaml index 6c190b69..3272d863 100644 --- a/example/service/udp/iperf_udp.yaml +++ b/example/service/udp/iperf_udp.yaml @@ -58,24 +58,24 @@ spec: apiVersion: apps/v1 kind: DaemonSet metadata: - name: iperf-client + name: iperf-client-udp labels: - app: iperf-client + app: iperf-client-udp spec: selector: matchLabels: - app: iperf-client + app: iperf-client-udp template: metadata: labels: - app: iperf-client + app: iperf-client-udp spec: tolerations: - key: node-role.kubernetes.io/master operator: Exists effect: NoSchedule containers: - - name: iperf-client + - name: iperf-client-udp image: lroktu/iperf command: ['/bin/sh', '-c', 'sleep infinity'] terminationGracePeriodSeconds: 0 diff --git a/inframanager/api_handler/api_handler.go b/inframanager/api_handler/api_handler.go index d86174dc..2d248f58 100644 --- a/inframanager/api_handler/api_handler.go +++ b/inframanager/api_handler/api_handler.go @@ -131,6 +131,8 @@ func OpenP4RtC(ctx context.Context, high uint64, low uint64, stopCh <-chan struc } log.Infof("P4Runtime server version is %s", resp.P4RuntimeApiVersion) + low = utils.MakeTimestampMilli() + electionID := p4_v1.Uint128{High: high, Low: low} server.p4RtC = client.NewClient(c, config.DeviceId, &electionID) log.Infof("Device id is: %v", config.DeviceId) diff --git a/pkg/inframanager/p4/service_es2k.go b/pkg/inframanager/p4/service_es2k.go index 43bb72a8..d0c9758c 100644 --- a/pkg/inframanager/p4/service_es2k.go +++ b/pkg/inframanager/p4/service_es2k.go @@ -297,12 +297,17 @@ func InsertServiceRules(ctx context.Context, p4RtC *client.Client, macByte = append(macByte, podmac) InterfaceIDbyte = append(InterfaceIDbyte, ValueToBytes16(uint16(epEntry.InterfaceID))) //L2 forwarding port + } else { + err := fmt.Errorf("Endpoint %s not found, cannot program service %s", + ep.PodIpAddress, service.ClusterIp) + return err, store.Service{} } + } service.NumEndPoints = epNum - log.Debugf("group id: %d, service ip: %s, service mac: %s, service port: %d", - groupID, service.ClusterIp, service.MacAddr, service.Port) + log.Debugf("group id: %d, service ip: %s, service mac: %s, service port: %d, endpoints: %d", + groupID, service.ClusterIp, service.MacAddr, service.Port, service.NumEndPoints) data := parseJson("service.json") if data == nil { @@ -330,9 +335,13 @@ func InsertServiceRules(ctx context.Context, p4RtC *client.Client, } entry := ep.GetFromStore() epEntry := entry.(store.EndPoint) + if entry == nil { + err = fmt.Errorf("epEntry does not exist for DefaultRoute") + return + } smacbyte, err := net.ParseMAC(epEntry.PodMacAddress) if err != nil { - err = fmt.Errorf("Invalid MAC Address") + err = fmt.Errorf("Invalid MAC Address for DefaultRoute") return } smac := []byte(smacbyte) @@ -503,7 +512,7 @@ func DeleteServiceRules(ctx context.Context, p4RtC *client.Client, //rx_src_ip log.Debugf("Deleting from table RxSrcIpTable, NumEp: %d, service ip: %s, service port: %d", - NumEp, podipByte, portIDByte) + NumEp, service.ClusterIp, uint16(service.Port)) key = append(key, podipByte) if service.Proto == "TCP" { key = append(key, ValueToBytes8(uint8(PROTO_TCP))) diff --git a/pkg/utils/common.go b/pkg/utils/common.go index 9f95860d..95f54598 100644 --- a/pkg/utils/common.go +++ b/pkg/utils/common.go @@ -19,6 +19,7 @@ import ( "io" "os" "path" + "time" log "github.com/sirupsen/logrus" ) @@ -79,3 +80,12 @@ func LogInit(logDir string, logLevel string) error { }) return nil } + +func unixMilli(t time.Time) uint64 { + s := t.Round(time.Millisecond).UnixNano() / (int64(time.Millisecond) / int64(time.Nanosecond)) + return uint64(s) +} + +func MakeTimestampMilli() uint64 { + return unixMilli(time.Now()) +}