Skip to content

Commit

Permalink
fix(gre-mesh): ensure bridge exists before creating GRE tunnels
Browse files Browse the repository at this point in the history
  • Loading branch information
activeshadow committed Jul 25, 2024
1 parent b22c528 commit 7b80f40
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 9 deletions.
20 changes: 20 additions & 0 deletions src/go/api/experiment/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,26 @@ func Start(ctx context.Context, opts ...StartOption) error {
}
}

// Creating experiment bridge after launching VMs to ensure the bridge
// already exists in minimega (and OVS) before creating GRE tunnels between
// them. This cannot be done as part of the minimega script template since
// the VM taps (and thus bridges) do not get created until the overall
// minimega namespace is launched.
if exp.Spec.UseGREMesh() || exp.Spec.DefaultBridge() != "phenix" {
if err := mm.CreateBridge(mm.NS(exp.Metadata.Name), mm.Bridge(exp.Spec.DefaultBridge())); err != nil {
if !o.mmErrAsWarn {
mm.ClearNamespace(exp.Spec.ExperimentName())
return fmt.Errorf("creating experiment bridge: %w", err)
}

if merr, ok := err.(*multierror.Error); ok {
notes.AddWarnings(ctx, false, merr.Errors...)
} else {
notes.AddWarnings(ctx, false, err)
}
}
}

schedule := make(map[string]string)

for _, vm := range mm.GetVMInfo(mm.NS(exp.Spec.ExperimentName())) {
Expand Down
4 changes: 0 additions & 4 deletions src/go/tmpl/templates/minimega_script.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ ns del-host all
ns add-host localhost
{{- end }}

{{- if or (ne .DefaultBridge "phenix") .UseGREMesh }}
ns bridge {{ .DefaultBridge }} gre
{{- end }}

{{- $basedir := .BaseDir }}

{{- range .Topology.Nodes }}
Expand Down
13 changes: 13 additions & 0 deletions src/go/util/mm/minimega.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,19 @@ func (Minimega) DisconnectVMInterface(opts ...Option) error {
return nil
}

func (Minimega) CreateBridge(opts ...Option) error {
o := NewOptions(opts...)

cmd := mmcli.NewNamespacedCommand(o.ns)
cmd.Command = fmt.Sprintf("ns bridge %s gre", o.bridge)

if err := mmcli.ErrorResponse(mmcli.Run(cmd)); err != nil {
return fmt.Errorf("creating bridge %s with GRE mesh between namespace hosts: %w", o.bridge, err)
}

return nil
}

func (Minimega) CreateTunnel(opts ...Option) error {
host, err := GetVMHost(opts...)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions src/go/util/mm/mm.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type MM interface {
ConnectVMInterface(...Option) error
DisconnectVMInterface(...Option) error

CreateBridge(...Option) error

CreateTunnel(...Option) error
GetTunnels(...Option) []map[string]string
CloseTunnel(...Option) error
Expand Down
17 changes: 12 additions & 5 deletions src/go/util/mm/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
type Option func(*options)

type options struct {
ns string
vm string
cpu int
mem int
disk string
ns string
vm string
cpu int
mem int
disk string
bridge string

injectPart int
injects []string
Expand Down Expand Up @@ -73,6 +74,12 @@ func Disk(d string) Option {
}
}

func Bridge(b string) Option {
return func(o *options) {
o.bridge = b
}
}

func InjectPartition(p int) Option {
return func(o *options) {
o.injectPart = p
Expand Down
4 changes: 4 additions & 0 deletions src/go/util/mm/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func DisconnectVMInterface(opts ...Option) error {
return DefaultMM.DisconnectVMInterface(opts...)
}

func CreateBridge(opts ...Option) error {
return DefaultMM.CreateBridge(opts...)
}

func CreateTunnel(opts ...Option) error {
return DefaultMM.CreateTunnel(opts...)
}
Expand Down

0 comments on commit 7b80f40

Please sign in to comment.