Skip to content

Commit

Permalink
Address most of the lll related lint issues (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
gab-arrobo authored May 30, 2024
1 parent 98fb03a commit 607ad37
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 19 deletions.
2 changes: 1 addition & 1 deletion internal/pfcpctl/commands/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
)

Expand Down
9 changes: 7 additions & 2 deletions internal/pfcpctl/commands/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
}

Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pfcpctl/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
26 changes: 17 additions & 9 deletions internal/pfcpsim/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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") {
Expand All @@ -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])
Expand Down
7 changes: 5 additions & 2 deletions internal/pfcpsim/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
17 changes: 13 additions & 4 deletions pkg/pfcpsim/pfcpsim.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 607ad37

Please sign in to comment.