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

Support hardware loopback for ixiatg #450

Merged
merged 3 commits into from
Oct 31, 2023
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: 0 additions & 1 deletion .github/linters/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ linters:
enable:
- gosec
- unconvert
- goconst
- goimports
- gofmt
- gocritic
Expand Down
6 changes: 6 additions & 0 deletions topo/node/keysight/keysight.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ func (n *Node) FixInterfaces() {
}
}

func (n *Node) BackToBackLoop() bool {
// IxiaTG supports back to back loops due to the node implementation creating
// a pod per port.
return true
}

func defaults(pb *tpb.Node) *tpb.Node {
if pb.Services == nil {
pb.Services = map[uint32]*tpb.Service{
Expand Down
9 changes: 9 additions & 0 deletions topo/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ type Implementation interface {
// Services provides a custom implementation for querying all services created for
// for a node. Requires context, Kubernetes client interface and namespace.
Services(context.Context) ([]*corev1.Service, error)
// BackToBackLoop returns a bool if the node supports links directly between
// two ports on the same node.
BackToBackLoop() bool
}

// Certer provides an interface for working with certs on nodes.
Expand Down Expand Up @@ -745,3 +748,9 @@ func (n *Impl) GetCLIConn(platform string, opts []scrapliutil.Option) (*scraplin
return d, nil
}
}

// BackToBackLoop returns a bool indicating if the node supports a single link
// connecting two ports on the same node. By default this is false.
func (n *Impl) BackToBackLoop() bool {
return false
}
11 changes: 8 additions & 3 deletions topo/topo.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,6 @@ func (m *Manager) load() error {
uid := 0
for _, l := range m.topo.Links {
log.Infof("Adding Link: %s:%s %s:%s", l.ANode, l.AInt, l.ZNode, l.ZInt)
if l.ANode == l.ZNode {
return fmt.Errorf("invalid link: hardware loopback %s:%s %s:%s not supported", l.ANode, l.AInt, l.ZNode, l.ZInt)
}
aNode, ok := nMap[l.ANode]
if !ok {
return fmt.Errorf("invalid topology: missing node %q", l.ANode)
Expand Down Expand Up @@ -474,6 +471,14 @@ func (m *Manager) load() error {
}
m.nodes[k] = nn
}
for _, l := range m.topo.Links {
aNode := m.nodes[l.ANode]
zNode := m.nodes[l.ZNode]
loop := aNode.BackToBackLoop() && zNode.BackToBackLoop()
if !loop && l.ANode == l.ZNode {
return fmt.Errorf("invalid link: back to back loop %s:%s %s:%s not supported", l.ANode, l.AInt, l.ZNode, l.ZInt)
}
}
return nil
}

Expand Down
37 changes: 37 additions & 0 deletions topo/topo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ func NewConfigurable(impl *node.Impl) (node.Node, error) {
return &configurable{Impl: impl}, nil
}

type loopbackable struct {
*node.Impl
}

func (l *loopbackable) BackToBackLoop() bool {
return true
}

func NewLoopbackable(impl *node.Impl) (node.Node, error) {
return &loopbackable{Impl: impl}, nil
}

type notConfigurable struct {
*node.Impl
}
Expand Down Expand Up @@ -141,6 +153,7 @@ func (nc *notCertable) GetProto() *tpb.Node {

func TestNew(t *testing.T) {
node.Vendor(tpb.Vendor(1001), NewConfigurable)
node.Vendor(tpb.Vendor(1006), NewLoopbackable)
tf, err := tfake.NewSimpleClientset()
if err != nil {
t.Fatalf("cannot create fake topology clientset: %v", err)
Expand Down Expand Up @@ -369,6 +382,30 @@ func TestNew(t *testing.T) {
},
},
wantErr: "invalid link",
}, {
desc: "loopback supported",
topo: &tpb.Topology{
Nodes: []*tpb.Node{
{
Name: "r1",
Vendor: tpb.Vendor(1006),
Services: map[uint32]*tpb.Service{
1000: {
Name: "ssh",
},
},
},
},
Links: []*tpb.Link{
{
ANode: "r1",
AInt: "eth1",
ZNode: "r1",
ZInt: "eth2",
},
},
},
wantNodes: []string{"r1"},
}}
for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
Expand Down