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
46 changes: 29 additions & 17 deletions src/go/app/startup.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ func (this Startup) PreStart(ctx context.Context, exp *types.Experiment) error {
node.General().SetDoNotBoot(true)
}

// if type is router, skip it and continue
if strings.EqualFold(node.Type(), "Router") {
continue
}


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this change... all of this should be in the vrouter app, not the startup app.

// Check to see if a scenario exists for this experiment and if it
// contains a "startup" app. If so, store it for later use
var startupApp ifaces.ScenarioApp
Expand All @@ -107,66 +103,82 @@ func (this Startup) PreStart(ctx context.Context, exp *types.Experiment) error {
startupApp = app
}
}

switch strings.ToLower(node.Hardware().OSType()) {
case "linux", "rhel", "centos":
var (
hostnameFile = startupDir + "/" + node.General().Hostname() + "-hostname.sh"
timezoneFile = startupDir + "/" + node.General().Hostname() + "-timezone.sh"
ifaceFile = startupDir + "/" + node.General().Hostname() + "-interfaces.sh"
)

node.AddInject(
hostnameFile,
"/etc/phenix/startup/1_hostname-start.sh",
"0755", "",
)

node.AddInject(
timezoneFile,
"/etc/phenix/startup/2_timezone-start.sh",
"0755", "",
)

node.AddInject(
ifaceFile,
"/etc/phenix/startup/3_interfaces-start.sh",
"0755", "",
)

timeZone := "Etc/UTC"

if err := tmpl.CreateFileFromTemplate("linux_hostname.tmpl", node.General().Hostname(), hostnameFile); err != nil {
return fmt.Errorf("generating linux hostname script: %w", err)
}

if err := tmpl.CreateFileFromTemplate("linux_timezone.tmpl", timeZone, timezoneFile); err != nil {
return fmt.Errorf("generating linux timezone script: %w", err)
}

if err := tmpl.CreateFileFromTemplate("linux_interfaces.tmpl", node, ifaceFile); err != nil {
return fmt.Errorf("generating linux interfaces script: %w", err)
}



if startupApp != nil {
for _, host := range startupApp.Hosts() {
if host.Hostname() == node.General().Hostname() {

var domainFile = startupDir + "/" + node.General().Hostname() + "-domain.sh"

node.AddInject(
domainFile,
"/etc/phenix/startup/4_domain-start.sh",
"0755", "",
)

if err := tmpl.CreateFileFromTemplate("linux_domain.tmpl", host.Metadata(), domainFile); err != nil {
return fmt.Errorf("generating linux domain script: %w", err)
}
}
}
}

if strings.EqualFold(node.Type(), "Router") {
var routerFile = startupDir + "/" + node.General().Hostname() + "-ospf.sh"

node.AddInject(
routerFile,
"/etc/phenix/startup/5_ospf-start.sh",
"0755", "",
)

if err := tmpl.CreateFileFromTemplate("linux_ospf.tmpl", host.Metadata(), routerFile); err != nil {
return fmt.Errorf("generating linux ospf script: %w", err)
}

}

case "windows":
startupFile := startupDir + "/" + node.General().Hostname() + "-startup.ps1"

Expand Down
3 changes: 3 additions & 0 deletions src/go/tmpl/templates/linux_interfaces.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ else
route add -net {{ $route.Destination }} gw {{ $route.Next }}
{{ end }}
fi


# frr ospf config
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the point of this comment?

14 changes: 14 additions & 0 deletions src/go/tmpl/templates/linux_ospf.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# Enable IP Forwarding
sysctl -w net.ipv4.conf.all.forwarding = 1

#check if frr exists
if command -v 'frr' &>/dev/null; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this check fails, that should probably be logged somewhere?

vtysh -d ospfd -c "configure terminal" -c "router ospf" -c "router-id .Network.Ospf.Router-id"
{{ range $area := .Network.Ospf.Areas}}
{{ range $network := $area.Area_networks}}
vtysh -d ospfd -c "configure terminal" -c "router ospf" -c "network {{ $network }} area {{ $area.Area_id }}"
{{ end }}
{{ end}}
fi