diff --git a/src/go/app/startup.go b/src/go/app/startup.go index cecdc5cd..d58ffc4f 100644 --- a/src/go/app/startup.go +++ b/src/go/app/startup.go @@ -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 - } - + // 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 @@ -107,7 +103,7 @@ func (this Startup) PreStart(ctx context.Context, exp *types.Experiment) error { startupApp = app } } - + switch strings.ToLower(node.Hardware().OSType()) { case "linux", "rhel", "centos": var ( @@ -115,51 +111,52 @@ func (this Startup) PreStart(ctx context.Context, exp *types.Experiment) error { 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) } @@ -167,6 +164,21 @@ func (this Startup) PreStart(ctx context.Context, exp *types.Experiment) error { } } + 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" diff --git a/src/go/tmpl/templates/linux_interfaces.tmpl b/src/go/tmpl/templates/linux_interfaces.tmpl index ccf9968b..c15910e1 100644 --- a/src/go/tmpl/templates/linux_interfaces.tmpl +++ b/src/go/tmpl/templates/linux_interfaces.tmpl @@ -55,3 +55,6 @@ else route add -net {{ $route.Destination }} gw {{ $route.Next }} {{ end }} fi + + +# frr ospf config diff --git a/src/go/tmpl/templates/linux_ospf.tmpl b/src/go/tmpl/templates/linux_ospf.tmpl new file mode 100644 index 00000000..8a1e4f32 --- /dev/null +++ b/src/go/tmpl/templates/linux_ospf.tmpl @@ -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 +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 \ No newline at end of file