Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix golangci-lint (final) #391

Merged
merged 1 commit into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion pfcpiface/bess.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"strconv"
"time"

"google.golang.org/grpc/credentials/insecure"

pb "github.com/omec-project/upf-epc/pfcpiface/bess_pb"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -529,7 +531,7 @@ func (b *bess) setUpfInfo(u *upf, conf *Conf) {

b.endMarkerChan = make(chan []byte, 1024)

b.conn, err = grpc.Dial(*bessIP, grpc.WithInsecure())
b.conn, err = grpc.Dial(*bessIP, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalln("did not connect:", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pfcpiface/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ func (node *PFCPNode) NewPFCPConn(lAddr, rAddr string, buf []byte) *PFCPConn {
}

// TODO: Get SEID range from PFCPNode for this PFCPConn

log.Infoln("Created PFCPConn from:", conn.LocalAddr(), "to:", conn.RemoteAddr())

rng := rand.New(rand.NewSource(time.Now().UnixNano())) // #nosec G404
p := &PFCPConn{
ctx: node.ctx,
Conn: conn,
ts: ts,
rng: rand.New(rand.NewSource(time.Now().UnixNano())),
rng: rng,
maxRetries: 100,
sessions: make(map[uint64]*PFCPSession),
upf: node.upf,
Expand Down
31 changes: 7 additions & 24 deletions pfcpiface/messages-conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,6 @@ func (pConn *PFCPConn) associationIEs() []*ie.IE {
return ies
}

func (pConn *PFCPConn) sendAssociationRequest() error {
upf := pConn.upf

if !upf.isConnected() {
return errFastpathDown
}

// Build request message
asreq := message.NewAssociationSetupRequest(pConn.getSeqNum(),
pConn.associationIEs()...,
)

pConn.SendPFCPMsg(asreq)

return nil
}

func (pConn *PFCPConn) handleAssociationSetupRequest(msg message.Message) (message.Message, error) {
addr := pConn.RemoteAddr().String()
upf := pConn.upf
Expand Down Expand Up @@ -151,33 +134,33 @@ func (pConn *PFCPConn) handleAssociationSetupRequest(msg message.Message) (messa
return asres, nil
}

func (pConn *PFCPConn) handleAssociationSetupResponse(msg message.Message) (message.Message, error) {
func (pConn *PFCPConn) handleAssociationSetupResponse(msg message.Message) error {
addr := pConn.RemoteAddr().String()

asres, ok := msg.(*message.AssociationSetupResponse)
if !ok {
return nil, errUnmarshal(errMsgUnexpectedType)
return errUnmarshal(errMsgUnexpectedType)
}

cause, err := asres.Cause.Cause()
if err != nil {
return nil, errUnmarshal(err)
return errUnmarshal(err)
}

if cause != ie.CauseRequestAccepted {
log.Errorln("Association Setup Response from", addr,
"with Cause:", cause)
return nil, errReqRejected
return errReqRejected
}

nodeID, err := asres.NodeID.NodeID()
if err != nil {
return nil, errUnmarshal(err)
return errUnmarshal(err)
}

ts, err := asres.RecoveryTimeStamp.RecoveryTimeStamp()
if err != nil {
return nil, errUnmarshal(err)
return errUnmarshal(err)
}

if pConn.ts.remote.IsZero() {
Expand All @@ -195,7 +178,7 @@ func (pConn *PFCPConn) handleAssociationSetupResponse(msg message.Message) (mess
log.Infoln("Association setup done between nodes",
"local:", pConn.nodeID.local, "remote:", pConn.nodeID.remote)

return nil, nil
return nil
}

func (pConn *PFCPConn) handleAssociationReleaseRequest(msg message.Message) (message.Message, error) {
Expand Down
14 changes: 7 additions & 7 deletions pfcpiface/messages-session.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,17 +497,17 @@ func (pConn *PFCPConn) handleDigestReport(fseid uint64) {
pConn.SendPFCPMsg(srreq)
}

func (pConn *PFCPConn) handleSessionReportResponse(msg message.Message) (message.Message, error) {
func (pConn *PFCPConn) handleSessionReportResponse(msg message.Message) error {
upf := pConn.upf

srres, ok := msg.(*message.SessionReportResponse)
if !ok {
return nil, errUnmarshal(errMsgUnexpectedType)
return errUnmarshal(errMsgUnexpectedType)
}

cause := srres.Cause.Payload[0]
if cause == ie.CauseRequestAccepted {
return nil, nil
return nil
}

log.Warnln("session req not accepted seq : ", srres.SequenceNumber)
Expand All @@ -517,7 +517,7 @@ func (pConn *PFCPConn) handleSessionReportResponse(msg message.Message) (message
if cause == ie.CauseSessionContextNotFound {
sessItem, ok := pConn.sessions[seid]
if !ok {
return nil, errProcess(ErrNotFoundWithParam("PFCP session context", "SEID", seid))
return errProcess(ErrNotFoundWithParam("PFCP session context", "SEID", seid))
}

log.Warnln("context not found, deleting session locally")
Expand All @@ -527,12 +527,12 @@ func (pConn *PFCPConn) handleSessionReportResponse(msg message.Message) (message
cause := upf.sendMsgToUPF(
upfMsgTypeDel, sessItem.pdrs, sessItem.fars, sessItem.qers)
if cause == ie.CauseRequestRejected {
return nil, errProcess(
return errProcess(
ErrOperationFailedWithParam("delete session from fastpath", "seid", seid))
}

return nil, nil
return nil
}

return nil, nil
return nil
}
4 changes: 2 additions & 2 deletions pfcpiface/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (pConn *PFCPConn) HandlePFCPMsg(buf []byte) {
}
// TODO: Cleanup sessions
case message.MsgTypeAssociationSetupResponse:
reply, err = pConn.handleAssociationSetupResponse(msg)
err = pConn.handleAssociationSetupResponse(msg)
// TODO: Cleanup sessions
// TODO: start heartbeats
case message.MsgTypeAssociationReleaseRequest:
Expand All @@ -99,7 +99,7 @@ func (pConn *PFCPConn) HandlePFCPMsg(buf []byte) {
case message.MsgTypeSessionDeletionRequest:
reply, err = pConn.handleSessionDeletionRequest(msg)
case message.MsgTypeSessionReportResponse:
_, err = pConn.handleSessionReportResponse(msg)
err = pConn.handleSessionReportResponse(msg)

// Incoming response messages
// TODO: Association Setup Request, Session Report Request
Expand Down
3 changes: 2 additions & 1 deletion pfcpiface/p4rt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package main

import (
"flag"
// #nosec G404 // Ignore G404. We don't need strong random number generator for allocating IDs for P4 objects.
"math/rand"
"net"
"time"
Expand Down Expand Up @@ -147,7 +148,7 @@ func getCounterVal(p *p4rtc, counterID uint8) (uint64, error) {
for i := 0; i < int(ctr.maxSize); i++ {
rand.Seed(time.Now().UnixNano())

val = uint64(rand.Intn(int(ctr.maxSize)-1) + 1)
val = uint64(rand.Intn(int(ctr.maxSize)-1) + 1) // #nosec G404
if _, ok := ctr.allocated[val]; !ok {
log.Println("key not in allocated map ", val)

Expand Down
7 changes: 6 additions & 1 deletion pfcpiface/p4rtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import (
"os"
"time"

"google.golang.org/grpc/credentials/insecure"

//nolint:staticcheck // Ignore SA1019.
// Upgrading to google.golang.org/protobuf/proto is not a drop-in replacement,
// as also P4Runtime stubs are based on the deprecated proto.
"github.com/golang/protobuf/proto"
grpcRetry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
p4ConfigV1 "github.com/p4lang/p4runtime/go/p4/config/v1"
Expand Down Expand Up @@ -1125,7 +1130,7 @@ func GetConnection(host string) (conn *grpc.ClientConn, err error) {
/* get connection */
log.Println("Get connection.")

conn, err = grpc.Dial(host, grpc.WithInsecure())
conn, err = grpc.Dial(host, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Println("grpc dial err: ", err)
return nil, err
Expand Down