Skip to content

Commit

Permalink
revistited genNodesFlag
Browse files Browse the repository at this point in the history
  • Loading branch information
hellt committed Apr 21, 2022
1 parent 6c911b2 commit 87885ab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
37 changes: 17 additions & 20 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ var interfaceFormat = map[string]string{
"bridge": "veth%d",
"vr-sros": "eth%d",
"vr-vmx": "eth%d",
"vr-vqfx": "eth%d",
"vr-xrv9k": "eth%d",
"vr-veos": "eth%d",
}
var supportedKinds = []string{"srl", "ceos", "linux", "bridge", "sonic-vs", "crpd", "vr-sros", "vr-vmx", "vr-xrv9k"}
var supportedKinds = []string{"srl", "ceos", "linux", "bridge", "sonic-vs", "crpd", "vr-sros", "vr-vmx", "vr-vqfx", "vr-xrv9k"}

const (
defaultSRLType = "ixrd2"
Expand Down Expand Up @@ -257,35 +258,31 @@ func parseNodesFlag(kind string, nodes ...string) ([]nodesDef, error) {
}
def.numNodes = uint(i)
switch len(items) {
// num_nodes notation
// kind is assumed to be `srl` or set with --kind
case 1:
if kind == "" {
log.Errorf("no kind specified for nodes '%s'", n)
return nil, errSyntax
}
def.kind = kind
if kind == "srl" {
def.typ = defaultSRLType
}
// num_nodes:kind notation
case 2:
switch items[1] {
case "ceos", "linux", "bridge", "sonic", "crpd":
def.kind = items[1]
case "srl":
def.kind = items[1]
def.typ = defaultSRLType
default:
// assume second item is a type if kind set using --kind
if kind == "" {
log.Errorf("no kind specified for nodes '%s'", n)
return nil, errSyntax
}
def.kind = kind
def.typ = items[1]
if kind == "" {
log.Errorf("no kind specified for nodes '%s'", n)
return nil, errSyntax
}
def.kind = items[1]

// num_nodes:kind:type notation
case 3:
// srl with #nodes, kind and type
def.numNodes = uint(i)
def.kind = items[1]
def.kind = kind

if items[1] != "" {
def.kind = items[1]
}

def.typ = items[2]
}
result[idx] = def
Expand Down
14 changes: 7 additions & 7 deletions cmd/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ var nodesTestSet = map[string]struct {
},
out: nodesOutput{
out: []nodesDef{
{numNodes: 1, kind: "srl", typ: "ixrd2"},
{numNodes: 2, kind: "srl", typ: "ixrd2"},
{numNodes: 3, kind: "srl", typ: "ixrd2"},
{numNodes: 1, kind: "srl", typ: ""},
{numNodes: 2, kind: "srl", typ: ""},
{numNodes: 3, kind: "srl", typ: ""},
},
err: nil,
},
Expand All @@ -142,7 +142,7 @@ var nodesTestSet = map[string]struct {
out: nodesOutput{
out: []nodesDef{
{numNodes: 1, kind: "linux", typ: ""},
{numNodes: 2, kind: "srl", typ: "ixrd2"},
{numNodes: 2, kind: "srl", typ: ""},
{numNodes: 3, kind: "ceos", typ: ""},
},
err: nil,
Expand All @@ -151,12 +151,12 @@ var nodesTestSet = map[string]struct {
"kind_nodes_with_kind_and_type": {
in: nodesInput{
kind: "srl",
nodes: []string{"1:ixrd", "2", "3:ceos"},
nodes: []string{"1::ixrd", "2", "3:ceos"},
},
out: nodesOutput{
out: []nodesDef{
{numNodes: 1, kind: "srl", typ: "ixrd"},
{numNodes: 2, kind: "srl", typ: "ixrd2"},
{numNodes: 2, kind: "srl"},
{numNodes: 3, kind: "ceos", typ: ""},
},
err: nil,
Expand All @@ -169,7 +169,7 @@ var nodesTestSet = map[string]struct {
},
out: nodesOutput{
out: []nodesDef{
{numNodes: 2, kind: "srl", typ: "ixrd2"},
{numNodes: 2, kind: "srl", typ: ""},
},
err: nil,
},
Expand Down

0 comments on commit 87885ab

Please sign in to comment.