From c78aedafac3f547dc03a694e8762345e5f1bec37 Mon Sep 17 00:00:00 2001 From: "Arrobo, Gabriel" Date: Thu, 30 May 2024 12:03:21 -0700 Subject: [PATCH] Address most of the `lll` related lint issues --- internal/pfcpctl/commands/services.go | 2 +- internal/pfcpctl/commands/sessions.go | 9 +++++++-- internal/pfcpctl/config/config.go | 2 +- internal/pfcpsim/helpers.go | 26 +++++++++++++++++--------- internal/pfcpsim/server.go | 7 +++++-- pkg/pfcpsim/pfcpsim.go | 17 +++++++++++++---- 6 files changed, 44 insertions(+), 19 deletions(-) diff --git a/internal/pfcpctl/commands/services.go b/internal/pfcpctl/commands/services.go index 82a9d0d..1c34eff 100644 --- a/internal/pfcpctl/commands/services.go +++ b/internal/pfcpctl/commands/services.go @@ -16,7 +16,7 @@ type ( disassociate struct{} configureRemoteAddresses struct { RemotePeerAddress string `short:"r" long:"remote-peer-addr" default:"" description:"The remote PFCP agent address."` - N3InterfaceAddress string `short:"n" long:"n3-addr" default:"" description:"The IPv4 address of the UPF's N3 interface"` + N3InterfaceAddress string `short:"n" long:"n3-addr" default:"" description:"UPF's N3 IP address"` } ) diff --git a/internal/pfcpctl/commands/sessions.go b/internal/pfcpctl/commands/sessions.go index eba267d..4696a64 100644 --- a/internal/pfcpctl/commands/sessions.go +++ b/internal/pfcpctl/commands/sessions.go @@ -40,7 +40,7 @@ type sessionModify struct { Args struct { commonArgs BufferFlag bool `short:"b" long:"buffer" description:"If set, downlink FARs will have the buffer flag set to true"` - NotifyCPFlag bool `short:"n" long:"notifycp" description:"If set, downlink FARs will have the notify CP flag set to true"` + NotifyCPFlag bool `short:"n" long:"notifycp" description:"Set true to have downlink FARs notify CP"` } } @@ -57,7 +57,12 @@ type SessionOptions struct { } func RegisterSessionCommands(parser *flags.Parser) { - _, err := parser.AddCommand("session", "Handle sessions", "Command to create/modify/delete sessions", &SessionOptions{}) + _, err := parser.AddCommand( + "session", + "Handle sessions", + "Command to create/modify/delete sessions", + &SessionOptions{}, + ) if err != nil { log.Warnln(err) } diff --git a/internal/pfcpctl/config/config.go b/internal/pfcpctl/config/config.go index 98138bb..8ffb115 100644 --- a/internal/pfcpctl/config/config.go +++ b/internal/pfcpctl/config/config.go @@ -15,7 +15,7 @@ const ( ) var GlobalOptions struct { - Server string `short:"s" long:"server" default:"" value-name:"SERVER:PORT" description:"IP/Host and port of pfcpsim gRPC Server"` + Server string `short:"s" long:"server" default:"" value-name:"SERVER:PORT" description:"gRPC Server IP/Host and port"` } type GlobalConfigSpec struct { diff --git a/internal/pfcpsim/helpers.go b/internal/pfcpsim/helpers.go index f0f5cae..5c346c4 100644 --- a/internal/pfcpsim/helpers.go +++ b/internal/pfcpsim/helpers.go @@ -68,7 +68,8 @@ func isRemotePeerConnected() bool { return remotePeerConnected } -// isNumOfAppFiltersCorrect returns error if the number of the passed filter exceed the max number of supported application filters. +// isNumOfAppFiltersCorrect returns error if the number of the passed filter +// exceed the max number of supported application filters. func isNumOfAppFiltersCorrect(filters []string) error { if len(filters) > SessionStep/2 { log.Errorf("Too many application filters: %v", filters) @@ -78,8 +79,9 @@ func isNumOfAppFiltersCorrect(filters []string) error { return nil } -// getLocalAddress returns the first IP address of the interfaceName, if specified, -// otherwise returns the IP address of the first non-loopback interface +// getLocalAddress returns the first IP address of the interfaceName, if +// specified, otherwise returns the IP address of the first non-loopback +// interface // Returns error if fail occurs at any stage. func getLocalAddress(interfaceName string) (net.IP, error) { addrs, err := net.InterfaceAddrs() @@ -111,8 +113,10 @@ func getLocalAddress(interfaceName string) (net.IP, error) { return nil, pfcpsim.NewNoValidInterfaceError() } -// ParseAppFilter parses an application filter. Returns a tuple formed by a formatted SDF filter -// and a uint8 representing the Application QER gate status and a precedence. Returns error if fail occurs while validating the filter string. +// ParseAppFilter parses an application filter. Returns a tuple formed by a +// formatted SDF filter and a uint8 representing the Application QER gate status +// and a precedence. Returns error if fail occurs while validating the filter +// string. func ParseAppFilter(filter string) (string, uint8, uint32, error) { if filter == "" { // parsing a wildcard app filter @@ -121,8 +125,9 @@ func ParseAppFilter(filter string) (string, uint8, uint32, error) { result := strings.Split(filter, ":") if len(result) != 5 { - return "", 0, 0, pfcpsim.NewInvalidFormatError("Parser was not able to generate the correct number of arguments." + - " Please make sure to use the right format") + return "", 0, 0, pfcpsim.NewInvalidFormatError( + "Parser was not able to generate the correct number of arguments." + + " Please make sure to use the right format") } proto, ipNetAddr, portRange, action, precedence := result[0], result[1], result[2], result[3], result[4] @@ -135,7 +140,8 @@ func ParseAppFilter(filter string) (string, uint8, uint32, error) { case "deny": gateStatus = ie.GateStatusClosed default: - return "", 0, 0, pfcpsim.NewInvalidFormatError("Action. Please make sure to use 'allow' or 'deny'") + return "", 0, 0, pfcpsim.NewInvalidFormatError( + "Action. Please make sure to use 'allow' or 'deny'") } if !(proto == "ip" || proto == "udp" || proto == "tcp") { @@ -159,7 +165,9 @@ func ParseAppFilter(filter string) (string, uint8, uint32, error) { if portRange != "any" { portList := strings.Split(portRange, "-") if !(len(portList) == 2) { - return "", 0, 0, pfcpsim.NewInvalidFormatError("Port range. Please make sure to use dash '-' to separate the two ports") + return "", 0, 0, pfcpsim.NewInvalidFormatError( + "Port range. Please make sure to use dash '-' to separate the two ports", + ) } lowerPort, err := strconv.Atoi(portList[0]) diff --git a/internal/pfcpsim/server.go b/internal/pfcpsim/server.go index 0c6523e..5c3f37d 100644 --- a/internal/pfcpsim/server.go +++ b/internal/pfcpsim/server.go @@ -65,8 +65,11 @@ func (P pfcpSimService) Configure(ctx context.Context, request *pb.ConfigureRequ SetRemotePeer(request.RemotePeerAddress) SetUpfN3(request.UpfN3Address) - configurationMsg := fmt.Sprintf("Server is configured. Remote peer address: %v, N3 interface address: %v ", remotePeerAddress, upfN3Address) - log.Info(configurationMsg) + configurationMsg := fmt.Sprintf( + "Server is configured. Remote peer address: %v, N3 interface address: %v ", + remotePeerAddress, + upfN3Address, + ) return &pb.Response{ StatusCode: int32(codes.OK), diff --git a/pkg/pfcpsim/pfcpsim.go b/pkg/pfcpsim/pfcpsim.go index 1a92ff7..4b788eb 100644 --- a/pkg/pfcpsim/pfcpsim.go +++ b/pkg/pfcpsim/pfcpsim.go @@ -273,8 +273,10 @@ func (c *PFCPClient) PeekNextResponse() (message.Message, error) { } } -// MsgTypeSessionReportRequest: sent by the UP function to the CP function to report information related to an PFCP session -// MsgTypeSessionReportResponse: sent by the CP function to the UP function as a reply to the Session Report Request. +// MsgTypeSessionReportRequest: sent by the UP function to the CP function to +// report information related to an PFCP session +// MsgTypeSessionReportResponse: sent by the CP function to the UP function as +// a reply to the Session Report Request. func (c *PFCPClient) handleSessionReportRequest(msg *message.SessionReportRequest) bool { if msg.MessageType() == message.MsgTypeSessionReportRequest { fmt.Println("Session Report Request received") @@ -322,7 +324,8 @@ func (c *PFCPClient) SendAssociationSetupRequest(ie ...*ieLib.IE) error { } // SendAssociationTeardownRequest sends PFCP Teardown Request towards a peer. -// A caller should make sure that the PFCP connection is established before invoking this function. +// A caller should make sure that the PFCP connection is established before +// invoking this function. func (c *PFCPClient) SendAssociationTeardownRequest(ie ...*ieLib.IE) error { raddr, err := net.ResolveUDPAddr("udp", c.remoteAddr) if err != nil { @@ -369,7 +372,13 @@ func (c *PFCPClient) SendSessionEstablishmentRequest(pdrs []*ieLib.IE, fars []*i return c.sendMsg(estReq) } -func (c *PFCPClient) SendSessionModificationRequest(PeerSEID uint64, pdrs []*ieLib.IE, qers []*ieLib.IE, fars []*ieLib.IE, urrs []*ieLib.IE) error { +func (c *PFCPClient) SendSessionModificationRequest( + PeerSEID uint64, + pdrs []*ieLib.IE, + qers []*ieLib.IE, + fars []*ieLib.IE, + urrs []*ieLib.IE, +) error { modifyReq := message.NewSessionModificationRequest( 0, 0,