Skip to content
Open
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
24 changes: 14 additions & 10 deletions Dockerfile.saibuilder
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
FROM us-west1-docker.pkg.dev/openconfig-lemming/internal/builder@sha256:6a960d06bfd63c9cd8cff1f2ab3b3cc21e578b570979b5574d232be644dd0bf9
FROM docker.io/debian:bookworm
WORKDIR /build
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libprotobuf-dev \
protobuf-compiler \
libgrpc++-dev \
protobuf-compiler-grpc \
libgoogle-glog-dev \
wget \
patch \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
COPY patches/sai.patch sai.patch
RUN wget -q https://github.com/opencomputeproject/SAI/archive/refs/tags/v1.14.0.tar.gz && tar xf v1.14.0.tar.gz && rm v1.14.0.tar.gz
RUN mkdir external && mv SAI-1.14.0 external/com_github_opencomputeproject_sai && patch -p1 -d external/com_github_opencomputeproject_sai < sai.patch
COPY go.* .
RUN wget -q https://github.com/opencomputeproject/SAI/archive/refs/tags/v1.15.0.tar.gz && tar xf v1.15.0.tar.gz && rm v1.15.0.tar.gz
RUN mkdir external && mv SAI-1.15.0 external/com_github_opencomputeproject_sai && patch -p1 -d external/com_github_opencomputeproject_sai < sai.patch
COPY dataplane/proto/sai/*.proto dataplane/proto/sai/
COPY dataplane/cpusink/*.go dataplane/cpusink/
COPY dataplane/standalone/packetio/*.go dataplane/standalone/packetio/
COPY dataplane/dplaneopts/*.go dataplane/dplaneopts/
COPY dataplane/forwarding/ dataplane/forwarding/
COPY dataplane/internal/kernel/*.go dataplane/internal/kernel/
COPY proto/forwarding/*.go proto/forwarding/
COPY dataplane/standalone/sai/*.cc dataplane/standalone/sai/
COPY dataplane/standalone/sai/*.h dataplane/standalone/sai/
COPY dataplane/standalone/entrypoint.cc dataplane/standalone/entrypoint.cc
Expand Down
22 changes: 22 additions & 0 deletions dataplane/forwarding/fwdconfig/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,25 @@ func (m *MirrorActionBuilder) set(a *fwdpb.ActionDesc) {
func (m *MirrorActionBuilder) actionType() fwdpb.ActionType {
return fwdpb.ActionType_ACTION_TYPE_MIRROR
}

// BridgeLearnActionBuilder is a builder for a bridge learn action.
type BridgeLearnActionBuilder struct {
tableID string
}

// BridgeLearnAction returns a new bridge learn action builder.
func BridgeLearnAction(tableID string) *BridgeLearnActionBuilder {
return &BridgeLearnActionBuilder{tableID: tableID}
}

func (b *BridgeLearnActionBuilder) set(a *fwdpb.ActionDesc) {
a.Action = &fwdpb.ActionDesc_Bridge{
Bridge: &fwdpb.BridgeLearnActionDesc{
TableId: &fwdpb.TableId{ObjectId: &fwdpb.ObjectId{Id: b.tableID}},
},
}
}

func (b *BridgeLearnActionBuilder) actionType() fwdpb.ActionType {
return fwdpb.ActionType_ACTION_TYPE_BRIDGE_LEARN
}
21 changes: 18 additions & 3 deletions dataplane/forwarding/fwdtable/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,29 @@ func (req *learnRequest) DebugString(port fwdport.Port) string {
// is buffered.
type Table struct {
*exact.Table // exact table containing mac entries
learn *queue.Queue // unbounded queue for learn requests
ctx *fwdcontext.Context // context for finding objects
notify chan bool // if not nil, a notification is generated when an entry is learned (test only)
learn *queue.Queue // unbounded queue for learn requests
ctx *fwdcontext.Context // context for finding objects
notify chan bool // if not nil, a notification is generated when an entry is learned (test only)
LearnCallback func(mac []byte, portID string)
}

// SetLearnCallback sets a callback invoked when a new MAC entry is dynamically learned.
func (t *Table) SetLearnCallback(cb func(mac []byte, portID string)) {
t.ctx.Lock()
defer t.ctx.Unlock()
t.LearnCallback = cb
}

// Clear clears the table by deleting all its entries.
func (t *Table) Clear() {
t.Table.Clear()
}

// Remove removes the entry matching the given MAC from the table.
func (t *Table) Remove(mac []byte) error {
return t.Table.RemoveKey(mac)
}

// Cleanup cleans up the exact match table and stops learning.
func (t *Table) Cleanup() {
t.learn.Close()
Expand Down Expand Up @@ -152,6 +165,8 @@ func (t *Table) processLearn(v interface{}) {
// we try to learn a mac address that has a static entry.
if err := t.AddEntry(desc, []*fwdpb.ActionDesc{&ad}); err != nil {
log.Infof("bridge: Skipping learn for %v %v.", req.DebugString(port), err)
} else if t.LearnCallback != nil {
t.LearnCallback(req.mac, string(fwdport.GetID(port).GetObjectId().GetId()))
}
}

Expand Down
21 changes: 21 additions & 0 deletions dataplane/forwarding/fwdtable/exact/exact.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ type Table struct {
func (t *Table) Clear() {
t.entriesMu.Lock()
defer t.entriesMu.Unlock()
if t.stale != nil {
t.staleMu.Lock()
t.stale.head = nil
t.stale.tail = nil
t.staleMu.Unlock()
}
for pos, head := range t.entries {
for entry := head; entry != nil; entry = entry.hashNext {
entry.actions.Cleanup()
Expand Down Expand Up @@ -307,6 +313,21 @@ func (t *Table) RemoveEntry(ed *fwdpb.EntryDesc) error {
return nil
}

// RemoveKey removes the entry associated with the given key.
func (t *Table) RemoveKey(key tableutil.Key) error {
entry := t.Find(key)
if entry == nil {
return fmt.Errorf("exact: RemoveKey failed, cannot find key %v", key)
}
if t.stale != nil && entry.transient {
t.staleMu.Lock()
t.stale.remove(entry)
t.staleMu.Unlock()
}
t.remove(entry)
return nil
}

// Entries lists all entries in a table. Note that the order of entries is
// non-deterministic.
func (t *Table) Entries() []string {
Expand Down
2 changes: 2 additions & 0 deletions dataplane/saiserver/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ go_library(
deps = [
"//dataplane/dplaneopts",
"//dataplane/forwarding",
"//dataplane/forwarding/fwdtable/bridge",
"//dataplane/forwarding/fwdconfig",
"//dataplane/forwarding/infra/fwdcontext",
"//dataplane/proto/packetio",
Expand All @@ -45,6 +46,7 @@ go_test(
srcs = [
"acl_test.go",
"bridge_test.go",
"fdb_test.go",
"hostif_test.go",
"l2mc_test.go",
"mirror_test.go",
Expand Down
16 changes: 16 additions & 0 deletions dataplane/saiserver/attrmgr/attrmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package attrmgr

import (
"strconv"
"context"
"fmt"
"log/slog"
Expand Down Expand Up @@ -385,3 +386,18 @@ func (mgr *AttrMgr) getID(req, resp proto.Message) (string, error) {
}
return string(pBytes), nil
}

// GetOIDsByType returns a list of OIDs that match the given ObjectType.
func (mgr *AttrMgr) GetOIDsByType(t saipb.ObjectType) []uint64 {
mgr.mu.Lock()
defer mgr.mu.Unlock()
var oids []uint64
for id, ty := range mgr.idToType {
if ty == t {
if oid, err := strconv.ParseUint(id, 10, 64); err == nil {
oids = append(oids, oid)
}
}
}
return oids
}
Loading