Skip to content

Commit

Permalink
Project import generated by Copybara.
Browse files Browse the repository at this point in the history
FolderOrigin-RevId: /usr/local/google/home/gdennis/copybara/temp/folder-destination5852504802352136234/.
  • Loading branch information
GGN Engprod Team authored and greg-dennis committed Mar 7, 2024
1 parent cee9eae commit 188f088
Show file tree
Hide file tree
Showing 6 changed files with 42,554 additions and 42,541 deletions.
8 changes: 6 additions & 2 deletions binding/portgraph/portgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,15 @@ type solver struct {
// Solve returns an assignment from superGraph that satisfies abstractGraph.
// Solve accepts a context to handle termination if the solve takes too long.
func Solve(ctx context.Context, abstractGraph *AbstractGraph, superGraph *ConcreteGraph) (*Assignment, error) {
solveErr := &SolveErr{absGraphDesc: abstractGraph.Desc, conGraphDesc: superGraph.Desc}
solveErr := &solveError{absGraphDesc: abstractGraph.Desc, conGraphDesc: superGraph.Desc}
if len(abstractGraph.Nodes) > len(superGraph.Nodes) {
solveErr.wrappedErr = fmt.Errorf("%q has %d nodes, but %q has %d nodes",
abstractGraph.Desc, len(abstractGraph.Nodes), superGraph.Desc, len(superGraph.Nodes))
return nil, solveErr

}
if len(abstractGraph.Edges) > len(superGraph.Edges) {
solveErr.wrappedErr = fmt.Errorf("%q has %d edges, but %q has %d edges",
abstractGraph.Desc, len(abstractGraph.Edges), superGraph.Desc, len(superGraph.Edges))
return nil, solveErr
}

Expand Down Expand Up @@ -260,6 +263,7 @@ func Solve(ctx context.Context, abstractGraph *AbstractGraph, superGraph *Concre

absPort2Port2Edge, err := abstractGraph.fetchPort2Port2EdgeMap()
if err != nil {
solveErr.wrappedErr = err
return nil, solveErr
}

Expand Down
2 changes: 1 addition & 1 deletion binding/portgraph/portgraph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ func TestSolveNotSolvable(t *testing.T) {
if err == nil {
t.Errorf("Solve got nil error, want error")
}
solveErr, ok := err.(*SolveErr)
solveErr, ok := err.(*solveError)
if !ok {
t.Fatal("Solve got not *SolveErr type err, want *SolveErr type")
}
Expand Down
49 changes: 30 additions & 19 deletions binding/portgraph/solve_err.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,43 @@ import (
"strings"
)

// SolveErr implements error and contains information about a call to Solve.
type SolveErr struct {
maxAssign *Assignment
absGraphDesc, conGraphDesc string
// solveError implements error and contains information about a call to Solve.
type solveError struct {
absGraphDesc string
conGraphDesc string
wrappedErr error
maxAssign *Assignment
}

func (s *solveError) Unwrap() error {
return s.wrappedErr
}

// Error returns and error string. This function implements error.
func (s *SolveErr) Error() string { return s.String() }
func (s *solveError) Error() string { return s.String() }

// String compiles SolveErr to a string format.
func (s *SolveErr) String() string {
func (s *solveError) String() string {
ret := &strings.Builder{}
fmt.Fprintf(ret, "Could not satisfy %q from %q\n", s.absGraphDesc, s.conGraphDesc)
fmt.Fprintf(ret, "\nMax assignment:\n")
for a, c := range s.maxAssign.Node2Node {
if c != nil {
fmt.Fprintf(ret, "Node %q is assigned to %q\n", a.Desc, c.Desc)
} else {
fmt.Fprintf(ret, "Node %q was not assigned\n", a.Desc)
}
fmt.Fprintf(ret, "Could not satisfy %q from %q", s.absGraphDesc, s.conGraphDesc)
if s.wrappedErr != nil {
fmt.Fprintf(ret, ": %v", s.wrappedErr)
}
for a, c := range s.maxAssign.Port2Port {
if c != nil {
fmt.Fprintf(ret, "Port %q is assigned to %q\n", a.Desc, c.Desc)
} else {
fmt.Fprintf(ret, "Port %q was not assigned\n", a.Desc)
if s.maxAssign != nil {
fmt.Fprintf(ret, "\nMax assignment:\n")
for a, c := range s.maxAssign.Node2Node {
if c != nil {
fmt.Fprintf(ret, "Node %q is assigned to %q\n", a.Desc, c.Desc)
} else {
fmt.Fprintf(ret, "Node %q was not assigned\n", a.Desc)
}
}
for a, c := range s.maxAssign.Port2Port {
if c != nil {
fmt.Fprintf(ret, "Port %q is assigned to %q\n", a.Desc, c.Desc)
} else {
fmt.Fprintf(ret, "Port %q was not assigned\n", a.Desc)
}
}
}
return ret.String()
Expand Down
2 changes: 1 addition & 1 deletion binding/portgraph/testbed.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestbedToAbstractGraph(tb *opb.Testbed, partial map[string]string) (*Abstra
}
edges = append(edges, &AbstractEdge{Src: src, Dst: dst})
}
return &AbstractGraph{Desc: "KNE testbed", Nodes: nodes, Edges: edges}, node2Dev, port2Port, nil
return &AbstractGraph{Desc: "Ondatra Testbed", Nodes: nodes, Edges: edges}, node2Dev, port2Port, nil
}

func modelConstraint(d *opb.Device) (NodeConstraint, bool) {
Expand Down
8 changes: 4 additions & 4 deletions gnmi/oc/networkinstance/networkinstance-0.go
Original file line number Diff line number Diff line change
Expand Up @@ -214393,8 +214393,8 @@ func (n *NetworkInstance_TableConnectionPathAny) DefaultImportPolicy() *NetworkI
// - IS-IS metric may be reflected in BGP MED (and vice versa)
// - OSPF metric may be reflected in the BGP MED (and vice versa)
// When this leaf is set to true, this reflection behaviour MUST be
// disabled, and rather the metric must be set to the default value,
// or explicitly set by policy.
// disabled, and rather the metric must be set to '0' or explicitly
// set by policy.
//
// Defining module: "openconfig-network-instance"
// Instantiating module: "openconfig-network-instance"
Expand All @@ -214418,8 +214418,8 @@ func (n *NetworkInstance_TableConnectionPath) DisableMetricPropagation() *Networ
// - IS-IS metric may be reflected in BGP MED (and vice versa)
// - OSPF metric may be reflected in the BGP MED (and vice versa)
// When this leaf is set to true, this reflection behaviour MUST be
// disabled, and rather the metric must be set to the default value,
// or explicitly set by policy.
// disabled, and rather the metric must be set to '0' or explicitly
// set by policy.
//
// Defining module: "openconfig-network-instance"
// Instantiating module: "openconfig-network-instance"
Expand Down
Loading

0 comments on commit 188f088

Please sign in to comment.