Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion fluent/fluent.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@

// Stop specifies that the gRIBI client should stop sending operations,
// and subsequently disconnect from the server.
func (g *GRIBIClient) Stop(t testing.TB) {

Check failure on line 214 in fluent/fluent.go

View workflow job for this annotation

GitHub Actions / go / Static Analysis

parameter 't' seems to be unused, consider removing or renaming it as _
if g.c != nil {
g.c.StopSending()
if err := g.c.Close(); err != nil {
Expand All @@ -235,7 +235,7 @@
// complete is defined as both the send and pending queue being empty, or an error
// being hit by the client. It returns an error in the case that there were errors
// reported.
func (g *GRIBIClient) Await(ctx context.Context, t testing.TB) error {

Check failure on line 238 in fluent/fluent.go

View workflow job for this annotation

GitHub Actions / go / Static Analysis

parameter 't' seems to be unused, consider removing or renaming it as _
if err := g.c.AwaitConverged(ctx); err != nil {
return err
}
Expand Down Expand Up @@ -304,7 +304,7 @@

const (
_ AFT = iota
AllAFTs

Check failure on line 307 in fluent/fluent.go

View workflow job for this annotation

GitHub Actions / go / Static Analysis

exported const AllAFTs should have comment (or a comment on this block) or be unexported
// IPv4 references the IPv4Entry AFT.
IPv4
// NextHopGroup references the NextHopGroupEntry AFT.
Expand Down Expand Up @@ -417,7 +417,7 @@
// entity into the modify stream. No validation of the input message is performed.
// It is intended to allow for invalid messages that the fluent library does not
// allow the creation of to be sent to a server.
func (g *gRIBIModify) InjectRequest(t testing.TB, m *spb.ModifyRequest) *gRIBIModify {

Check failure on line 420 in fluent/fluent.go

View workflow job for this annotation

GitHub Actions / go / Static Analysis

parameter 't' seems to be unused, consider removing or renaming it as _
g.parent.c.Q(m)
return g
}
Expand Down Expand Up @@ -454,7 +454,7 @@

// Enqueue adds the pre-formed set of ModifyRequests to the queue that are to be
// sent by the client. The entries are not validated or modified.
func (g *gRIBIModify) Enqueue(t testing.TB, entries ...*spb.ModifyRequest) *gRIBIModify {

Check failure on line 457 in fluent/fluent.go

View workflow job for this annotation

GitHub Actions / go / Static Analysis

parameter 't' seems to be unused, consider removing or renaming it as _
for _, m := range entries {
g.parent.c.Q(m)
}
Expand All @@ -463,7 +463,7 @@

// UpdateElectionID updates the election ID on the gRIBI Modify channel using value provided.
// The election ID is a uint128 made up of concatenating the low and high uint64 values provided.
func (g *gRIBIModify) UpdateElectionID(t testing.TB, low, high uint64) *gRIBIModify {

Check failure on line 466 in fluent/fluent.go

View workflow job for this annotation

GitHub Actions / go / Static Analysis

parameter 't' seems to be unused, consider removing or renaming it as _
eid := &spb.Uint128{
Low: low,
High: high,
Expand Down Expand Up @@ -939,18 +939,25 @@
pb *aftpb.Afts_NextHop_EncapHeader
}

// UDPEncapHeader represents a UDP encapsulation header.
// udpv6EncapHeader represents a UDP encapsulation header.
type udpv6EncapHeader struct {
pb *aftpb.Afts_NextHop_EncapHeader
}

// udpv4EncapHeader represents a UDP encapsulation header.
type udpv4EncapHeader struct {
pb *aftpb.Afts_NextHop_EncapHeader
}

const (
_ Header = iota
// IPinIP specifies that the header to be decpsulated is an IPv4 header, and is typically
// used when IP-in-IP tunnels are created.
IPinIP
// MPLS specifies that the header to be decapsulated is an MPLS header.
MPLS
// UDPV4 specifies that the header to be decapsulated is a UDPv4 header.
UDPV4
// UDPV6 specifies that the header to be decapsulated is a UDPv6 header.
UDPV6
)
Expand All @@ -960,6 +967,7 @@
var encapMap = map[Header]enums.OpenconfigAftTypesEncapsulationHeaderType{
IPinIP: enums.OpenconfigAftTypesEncapsulationHeaderType_OPENCONFIGAFTTYPESENCAPSULATIONHEADERTYPE_IPV4,
MPLS: enums.OpenconfigAftTypesEncapsulationHeaderType_OPENCONFIGAFTTYPESENCAPSULATIONHEADERTYPE_MPLS,
UDPV4: enums.OpenconfigAftTypesEncapsulationHeaderType_OPENCONFIGAFTTYPESENCAPSULATIONHEADERTYPE_UDPV4,
UDPV6: enums.OpenconfigAftTypesEncapsulationHeaderType_OPENCONFIGAFTTYPESENCAPSULATIONHEADERTYPE_UDPV6,
}

Expand Down Expand Up @@ -1069,6 +1077,57 @@
return eh.pb
}

// UDPV4EncapHeader returns a builder that can be used to build up a UDPv4 encapsulation header.
func UDPV4EncapHeader() *udpv4EncapHeader {
Comment thread
keysightgems marked this conversation as resolved.
return &udpv4EncapHeader{
pb: &aftpb.Afts_NextHop_EncapHeader{
Type: encapMap[UDPV4],
UdpV4: &aftpb.Afts_NextHop_EncapHeader_UdpV4{},
},
}
}

// WithDSCP specifies the DSCP value to be used for the UDPv4 header.
func (eh *udpv4EncapHeader) WithDSCP(dscp uint64) *udpv4EncapHeader {
eh.pb.UdpV4.Dscp = &wpb.UintValue{Value: dscp}
return eh
}

// WithDstIP specifies the destination IP to be used for the UDPv4 header.
func (eh *udpv4EncapHeader) WithDstIP(ip string) *udpv4EncapHeader {
eh.pb.UdpV4.DstIp = &wpb.StringValue{Value: ip}
return eh
}

// WithDstUDPPort specifies the destination UDP port to be used for the UDPv4 header.
func (eh *udpv4EncapHeader) WithDstUDPPort(port uint64) *udpv4EncapHeader {
eh.pb.UdpV4.DstUdpPort = &wpb.UintValue{Value: port}
return eh
}

// WithIPTTL specifies the IP TTL to be used for the UDPv4 header.
func (eh *udpv4EncapHeader) WithIPTTL(ttl uint64) *udpv4EncapHeader {
eh.pb.UdpV4.IpTtl = &wpb.UintValue{Value: ttl}
return eh
}

// WithSrcIP specifies the source IP to be used for the UDPv4 header.
func (eh *udpv4EncapHeader) WithSrcIP(ip string) *udpv4EncapHeader {
eh.pb.UdpV4.SrcIp = &wpb.StringValue{Value: ip}
return eh
}

// WithSrcUDPPort specifies the source UDP port to be used for the UDPv4 header.
func (eh *udpv4EncapHeader) WithSrcUDPPort(port uint64) *udpv4EncapHeader {
eh.pb.UdpV4.SrcUdpPort = &wpb.UintValue{Value: port}
return eh
}

// EncapProto returns the built-up protobuf of the udpv4EncapHeader.
func (eh *udpv4EncapHeader) EncapProto() *aftpb.Afts_NextHop_EncapHeader {
return eh.pb
}

// WithElectionID specifies an explicit election ID that is to be used hen the next hop
// is programmed in an AFTOperation. The electionID is a uint128 made up of concatenating
// the low and high uint64 values provided.
Expand Down Expand Up @@ -1208,12 +1267,12 @@

const (
_ ModifyErrReason = iota
// Unsupported parameters indicates that the server does not support the client parameters.

Check failure on line 1270 in fluent/fluent.go

View workflow job for this annotation

GitHub Actions / go / Static Analysis

comment on exported const UnsupportedParameters should be of the form "UnsupportedParameters ..."
UnsupportedParameters
// ModifyParamsNotAllowed indicates that the client tried to modify the parameters after they
// were set.
ModifyParamsNotAllowed
// ParamsDiffereFromOtherClients indicates that the parameters specified are inconsistent

Check failure on line 1275 in fluent/fluent.go

View workflow job for this annotation

GitHub Actions / go / Static Analysis

comment on exported const ParamsDifferFromOtherClients should be of the form "ParamsDifferFromOtherClients ..."
// with other clients that are connected to the server.
ParamsDifferFromOtherClients
// ElectionIDNotAllowed indicates that a client tried to send an election ID in a context
Expand Down
85 changes: 85 additions & 0 deletions fluent/fluent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,91 @@ func TestEntry(t *testing.T) {
},
},
},
}, {
desc: "next-hop mpls-over-udpv4",
in: NextHopEntry().
WithNetworkInstance("DEFAULT").
WithIndex(1).
AddEncapHeader(
MPLSEncapHeader().WithLabels(100, 200),
UDPV4EncapHeader().WithDSCP(10).WithDstIP("192.0.2.1").WithDstUDPPort(5678).WithIPTTL(32).WithSrcIP("192.0.2.2").WithSrcUDPPort(8765),
),
wantOpProto: &spb.AFTOperation{
NetworkInstance: "DEFAULT",
Entry: &spb.AFTOperation_NextHop{
NextHop: &aftpb.Afts_NextHopKey{
Index: 1,
NextHop: &aftpb.Afts_NextHop{
EncapHeader: []*aftpb.Afts_NextHop_EncapHeaderKey{
{
Index: 1,
EncapHeader: &aftpb.Afts_NextHop_EncapHeader{
Type: enums.OpenconfigAftTypesEncapsulationHeaderType_OPENCONFIGAFTTYPESENCAPSULATIONHEADERTYPE_MPLS,
Mpls: &aftpb.Afts_NextHop_EncapHeader_Mpls{
MplsLabelStack: []*aftpb.Afts_NextHop_EncapHeader_Mpls_MplsLabelStackUnion{
{MplsLabelStackUint64: uint64(100)},
{MplsLabelStackUint64: uint64(200)},
},
},
},
},
{
Index: 2,
EncapHeader: &aftpb.Afts_NextHop_EncapHeader{
Type: enums.OpenconfigAftTypesEncapsulationHeaderType_OPENCONFIGAFTTYPESENCAPSULATIONHEADERTYPE_UDPV4,
UdpV4: &aftpb.Afts_NextHop_EncapHeader_UdpV4{
Dscp: &wpb.UintValue{Value: uint64(10)},
DstIp: &wpb.StringValue{Value: "192.0.2.1"},
DstUdpPort: &wpb.UintValue{Value: uint64(5678)},
IpTtl: &wpb.UintValue{Value: uint64(32)},
SrcIp: &wpb.StringValue{Value: "192.0.2.2"},
SrcUdpPort: &wpb.UintValue{Value: uint64(8765)},
},
},
},
},
},
},
},
},
wantEntryProto: &spb.AFTEntry{
NetworkInstance: "DEFAULT",
Entry: &spb.AFTEntry_NextHop{
NextHop: &aftpb.Afts_NextHopKey{
Index: 1,
NextHop: &aftpb.Afts_NextHop{
EncapHeader: []*aftpb.Afts_NextHop_EncapHeaderKey{
{
Index: 1,
EncapHeader: &aftpb.Afts_NextHop_EncapHeader{
Type: enums.OpenconfigAftTypesEncapsulationHeaderType_OPENCONFIGAFTTYPESENCAPSULATIONHEADERTYPE_MPLS,
Mpls: &aftpb.Afts_NextHop_EncapHeader_Mpls{
MplsLabelStack: []*aftpb.Afts_NextHop_EncapHeader_Mpls_MplsLabelStackUnion{
{MplsLabelStackUint64: uint64(100)},
{MplsLabelStackUint64: uint64(200)},
},
},
},
},
{
Index: 2,
EncapHeader: &aftpb.Afts_NextHop_EncapHeader{
Type: enums.OpenconfigAftTypesEncapsulationHeaderType_OPENCONFIGAFTTYPESENCAPSULATIONHEADERTYPE_UDPV4,
UdpV4: &aftpb.Afts_NextHop_EncapHeader_UdpV4{
Dscp: &wpb.UintValue{Value: uint64(10)},
DstIp: &wpb.StringValue{Value: "192.0.2.1"},
DstUdpPort: &wpb.UintValue{Value: uint64(5678)},
IpTtl: &wpb.UintValue{Value: uint64(32)},
SrcIp: &wpb.StringValue{Value: "192.0.2.2"},
SrcUdpPort: &wpb.UintValue{Value: uint64(8765)},
},
},
},
},
},
},
},
},
}}

for _, tt := range tests {
Expand Down
Loading