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

MyMac initialization and action configuration #377

Merged
merged 8 commits into from
Mar 15, 2024
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
1 change: 1 addition & 0 deletions dataplane/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ go_library(
"@com_github_openconfig_ygnmi//ygnmi",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//credentials/local",
"@org_golang_google_protobuf//proto",
] + select({
"@io_bazel_rules_go//go/platform:aix": [
"//dataplane/dplanerc",
Expand Down
4 changes: 4 additions & 0 deletions dataplane/saiserver/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ type myMacInfo struct {

// ToEntryDesc returns the EntryDesc.
func (mi *myMacInfo) ToEntryDesc(m *myMac) (*fwdpb.EntryDesc, error) {
if mi.priority == nil {
return nil, fmt.Errorf("priority needs to be specified")
}
fields := []*fwdconfig.PacketFieldMaskedBytesBuilder{
fwdconfig.PacketFieldMaskedBytes(fwdpb.PacketFieldNum_PACKET_FIELD_NUM_ETHER_MAC_DST).
WithBytes(mi.macAddress, mi.macAddressMask),
Expand Down Expand Up @@ -382,6 +385,7 @@ func (m *myMac) CreateMyMac(ctx context.Context, req *saipb.CreateMyMacRequest)
ContextId: &fwdpb.ContextId{Id: m.dataplane.ID()},
TableId: &fwdpb.TableId{ObjectId: &fwdpb.ObjectId{Id: MyMacTable}},
EntryDesc: ed,
Actions: []*fwdpb.ActionDesc{{ActionType: fwdpb.ActionType_ACTION_TYPE_CONTINUE}},
}

if _, err := m.dataplane.TableEntryAdd(ctx, mReq); err != nil {
Expand Down
1 change: 1 addition & 0 deletions dataplane/saiserver/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ var getInterface = net.InterfaceByName

func getForwardingPipeline() []*fwdpb.ActionDesc {
return []*fwdpb.ActionDesc{
fwdconfig.Action(fwdconfig.LookupAction(MyMacTable)).Build(), // Decide whether to process the packet.
fwdconfig.Action(fwdconfig.LookupAction(inputIfaceTable)).Build(), // Match packet to interface.
fwdconfig.Action(fwdconfig.LookupAction(IngressVRFTable)).Build(), // Match interface to VRF.
fwdconfig.Action(fwdconfig.LookupAction(PreIngressActionTable)).Build(), // Run pre-ingress actions.
Expand Down
1 change: 1 addition & 0 deletions dataplane/saiserver/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ func (sw *saiSwitch) CreateSwitch(ctx context.Context, _ *saipb.CreateSwitchRequ
Desc: &fwdpb.TableDesc{
TableType: fwdpb.TableType_TABLE_TYPE_FLOW,
TableId: &fwdpb.TableId{ObjectId: &fwdpb.ObjectId{Id: MyMacTable}},
Actions: []*fwdpb.ActionDesc{{ActionType: fwdpb.ActionType_ACTION_TYPE_DROP}},
Table: &fwdpb.TableDesc_Flow{
Flow: &fwdpb.FlowTableDesc{
BankCount: 1,
Expand Down
13 changes: 13 additions & 0 deletions dataplane/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/openconfig/ygnmi/ygnmi"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/local"
"google.golang.org/protobuf/proto"

"github.com/openconfig/lemming/dataplane/dplaneopts"
"github.com/openconfig/lemming/dataplane/saiserver"
Expand Down Expand Up @@ -104,6 +105,18 @@ func (d *Dataplane) Start(ctx context.Context, c gpb.GNMIClient, target string)
return err
}

// Allow all traffic to L3 processing.
mmc := saipb.NewMyMacClient(conn)
_, err = mmc.CreateMyMac(context.Background(), &saipb.CreateMyMacRequest{
Switch: swResp.Oid,
Priority: proto.Uint32(1),
MacAddress: []byte{0, 0, 0, 0, 0, 0},
MacAddressMask: []byte{0, 0, 0, 0, 0, 0},
})
if err != nil {
return err
}

_, err = hostif.CreateHostifTrap(ctx, &saipb.CreateHostifTrapRequest{
Switch: swResp.Oid,
TrapType: saipb.HostifTrapType_HOSTIF_TRAP_TYPE_ARP_REQUEST.Enum(),
Expand Down
29 changes: 24 additions & 5 deletions integration_tests/dataplane/basictraffic/basic_traffic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package basictraffic

import (
"context"
"net"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -52,6 +53,7 @@ const (
var (
dutPort1 = attrs.Attributes{
Desc: "dutPort1",
MAC: "10:10:10:10:10:10",
IPv4: "192.0.2.1",
IPv4Len: ipv4PrefixLen,
}
Expand All @@ -65,6 +67,7 @@ var (

dutPort2 = attrs.Attributes{
Desc: "dutPort2",
MAC: "10:10:10:10:10:11",
IPv4: "192.0.2.5",
IPv4Len: ipv4PrefixLen,
}
Expand Down Expand Up @@ -108,21 +111,37 @@ func configureDUT(t testing.TB, dut *ondatra.DUTDevice) {
if err != nil {
t.Fatal(err)
}
// Allow all traffic to L3 processing.
mmc := saipb.NewMyMacClient(conn)
_, err = mmc.CreateMyMac(context.Background(), &saipb.CreateMyMacRequest{
Switch: 1,
Priority: proto.Uint32(1),
MacAddress: []byte{0, 0, 0, 0, 0, 0},
MacAddressMask: []byte{0, 0, 0, 0, 0, 0},
})

mac1, err := net.ParseMAC(dutPort1.MAC)
if err != nil {
t.Fatal(err)
}
_, err = ric.CreateRouterInterface(context.Background(), &saipb.CreateRouterInterfaceRequest{
Switch: 1,
PortId: proto.Uint64(port1ID),
Type: saipb.RouterInterfaceType_ROUTER_INTERFACE_TYPE_PORT.Enum(),
SrcMacAddress: []byte{10, 10, 10, 10, 10, 10},
SrcMacAddress: mac1,
})
if err != nil {
t.Fatal(err)
}
mac2, err := net.ParseMAC(dutPort2.MAC)
if err != nil {
t.Fatal(err)
}
rif2Resp, err := ric.CreateRouterInterface(context.Background(), &saipb.CreateRouterInterfaceRequest{
Switch: 1,
PortId: proto.Uint64(port2ID),
Type: saipb.RouterInterfaceType_ROUTER_INTERFACE_TYPE_PORT.Enum(),
SrcMacAddress: []byte{10, 10, 10, 10, 10, 11},
SrcMacAddress: mac2,
})
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -168,7 +187,7 @@ func TestTraffic(t *testing.T) {
dut := ondatra.DUT(t, "dut")
configureDUT(t, dut)

loss := testTraffic(t, ate, ateTop, atePort1, atePort2, 10*time.Second)
loss := testTraffic(t, ate, ateTop, atePort1, dutPort1, atePort2, 10*time.Second)
if loss > 1 {
t.Errorf("loss %f, greater than 1", loss)
}
Expand All @@ -189,7 +208,7 @@ func configureATE(t *testing.T, ate *ondatra.ATEDevice) gosnappi.Config {
// testTraffic generates traffic flow from source network to
// destination network via srcEndPoint to dstEndPoint and checks for
// packet loss and returns loss percentage as float.
func testTraffic(t *testing.T, ate *ondatra.ATEDevice, top gosnappi.Config, srcEndPoint, dstEndPoint attrs.Attributes, dur time.Duration) float32 {
func testTraffic(t *testing.T, ate *ondatra.ATEDevice, top gosnappi.Config, srcEndPoint, srcPeerEndpoint, dstEndPoint attrs.Attributes, dur time.Duration) float32 {
otg := ate.OTG()
top.Flows().Clear().Items()

Expand All @@ -206,7 +225,7 @@ func testTraffic(t *testing.T, ate *ondatra.ATEDevice, top gosnappi.Config, srcE
// Set up ethernet layer.
eth := ipFLow.Packet().Add().Ethernet()
eth.Src().SetValue(srcEndPoint.MAC)
eth.Dst().SetValue(dstEndPoint.MAC)
eth.Dst().SetValue(srcPeerEndpoint.MAC)

ip4 := ipFLow.Packet().Add().Ipv4()
ip4.Src().SetValue(srcEndPoint.IPv4)
Expand Down
Loading