|
@@ -3483,7 +3483,7 @@ func (e *Executor) handleRoutingBabel(parts []string, user *auth.PublicUser) str
|
|
|
func (e *Executor) handleBabelInstance(parts []string, user *auth.PublicUser) string {
|
|
func (e *Executor) handleBabelInstance(parts []string, user *auth.PublicUser) string {
|
|
|
if len(parts) == 0 || parts[0] == "print" || parts[0] == "pr" {
|
|
if len(parts) == 0 || parts[0] == "print" || parts[0] == "pr" {
|
|
|
instances := e.dynRoutingMgr.ListBabelInstances()
|
|
instances := e.dynRoutingMgr.ListBabelInstances()
|
|
|
- tbl := NewTable("#", "FLAGS", "NAME", "ROUTER-ID", "REDISTRIBUTE", "METRIC", "STATUS")
|
|
|
|
|
|
|
+ tbl := NewTable("#", "FLAGS", "NAME", "ROUTER-ID", "IN-FILTER", "OUT-FILTER", "REDISTRIBUTE", "METRIC", "STATUS")
|
|
|
for idx, inst := range instances {
|
|
for idx, inst := range instances {
|
|
|
st := "enabled"
|
|
st := "enabled"
|
|
|
flags := "I"
|
|
flags := "I"
|
|
@@ -3518,7 +3518,15 @@ func (e *Executor) handleBabelInstance(parts []string, user *auth.PublicUser) st
|
|
|
if rID == "" {
|
|
if rID == "" {
|
|
|
rID = "auto"
|
|
rID = "auto"
|
|
|
}
|
|
}
|
|
|
- tbl.AddRow(fmt.Sprintf("%d", idx), flags, inst.Name, rID, redistStr, fmt.Sprintf("%d", inst.DefaultMetric), st)
|
|
|
|
|
|
|
+ inF := inst.InFilter
|
|
|
|
|
+ if inF == "" {
|
|
|
|
|
+ inF = "-"
|
|
|
|
|
+ }
|
|
|
|
|
+ outF := inst.OutFilter
|
|
|
|
|
+ if outF == "" {
|
|
|
|
|
+ outF = "-"
|
|
|
|
|
+ }
|
|
|
|
|
+ tbl.AddRow(fmt.Sprintf("%d", idx), flags, inst.Name, rID, inF, outF, redistStr, fmt.Sprintf("%d", inst.DefaultMetric), st)
|
|
|
}
|
|
}
|
|
|
return tbl.String()
|
|
return tbl.String()
|
|
|
}
|
|
}
|
|
@@ -3538,6 +3546,8 @@ func (e *Executor) handleBabelInstance(parts []string, user *auth.PublicUser) st
|
|
|
inst := dynamicrouting.BabelInstance{
|
|
inst := dynamicrouting.BabelInstance{
|
|
|
Name: name,
|
|
Name: name,
|
|
|
RouterID: params["router-id"],
|
|
RouterID: params["router-id"],
|
|
|
|
|
+ InFilter: params["in-filter"],
|
|
|
|
|
+ OutFilter: params["out-filter"],
|
|
|
Enabled: true,
|
|
Enabled: true,
|
|
|
Disabled: false,
|
|
Disabled: false,
|
|
|
RedistributeConnected: parseCLIEnableDisable(params["redistribute-connected"], false),
|
|
RedistributeConnected: parseCLIEnableDisable(params["redistribute-connected"], false),
|
|
@@ -3551,6 +3561,68 @@ func (e *Executor) handleBabelInstance(parts []string, user *auth.PublicUser) st
|
|
|
}
|
|
}
|
|
|
return ColorGreen + fmt.Sprintf("Babel instance %s added.\n", name) + ColorReset
|
|
return ColorGreen + fmt.Sprintf("Babel instance %s added.\n", name) + ColorReset
|
|
|
|
|
|
|
|
|
|
+ case "set":
|
|
|
|
|
+ pos, params := parseArgs(parts[1:])
|
|
|
|
|
+ target := ""
|
|
|
|
|
+ if len(pos) > 0 {
|
|
|
|
|
+ target = pos[0]
|
|
|
|
|
+ } else if v, ok := params["numbers"]; ok {
|
|
|
|
|
+ target = v
|
|
|
|
|
+ } else if v, ok := params["name"]; ok {
|
|
|
|
|
+ target = v
|
|
|
|
|
+ }
|
|
|
|
|
+ if target == "" {
|
|
|
|
|
+ return ColorRed + "Usage: /routing babel instance set <#|name|id> [in-filter=...] [out-filter=...] [router-id=...] [default-metric=...]\n" + ColorReset
|
|
|
|
|
+ }
|
|
|
|
|
+ instances := e.dynRoutingMgr.ListBabelInstances()
|
|
|
|
|
+ var targetInst *dynamicrouting.BabelInstance
|
|
|
|
|
+ if idx, err := strconv.Atoi(target); err == nil && idx >= 0 && idx < len(instances) {
|
|
|
|
|
+ targetInst = &instances[idx]
|
|
|
|
|
+ } else {
|
|
|
|
|
+ for i := range instances {
|
|
|
|
|
+ if strings.EqualFold(instances[i].Name, target) || instances[i].ID == target {
|
|
|
|
|
+ targetInst = &instances[i]
|
|
|
|
|
+ break
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if targetInst == nil {
|
|
|
|
|
+ return ColorRed + "Babel instance not found: " + target + "\n" + ColorReset
|
|
|
|
|
+ }
|
|
|
|
|
+ if v, ok := params["in-filter"]; ok {
|
|
|
|
|
+ targetInst.InFilter = strings.TrimSpace(v)
|
|
|
|
|
+ }
|
|
|
|
|
+ if v, ok := params["out-filter"]; ok {
|
|
|
|
|
+ targetInst.OutFilter = strings.TrimSpace(v)
|
|
|
|
|
+ }
|
|
|
|
|
+ if v, ok := params["router-id"]; ok {
|
|
|
|
|
+ targetInst.RouterID = strings.TrimSpace(v)
|
|
|
|
|
+ }
|
|
|
|
|
+ if v, ok := params["default-metric"]; ok {
|
|
|
|
|
+ if m, err := strconv.Atoi(v); err == nil && m > 0 {
|
|
|
|
|
+ targetInst.DefaultMetric = m
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if v, ok := params["redistribute-connected"]; ok {
|
|
|
|
|
+ targetInst.RedistributeConnected = parseCLIEnableDisable(v, targetInst.RedistributeConnected)
|
|
|
|
|
+ }
|
|
|
|
|
+ if v, ok := params["redistribute-static"]; ok {
|
|
|
|
|
+ targetInst.RedistributeStatic = parseCLIEnableDisable(v, targetInst.RedistributeStatic)
|
|
|
|
|
+ }
|
|
|
|
|
+ if v, ok := params["redistribute-bgp"]; ok {
|
|
|
|
|
+ targetInst.RedistributeBGP = parseCLIEnableDisable(v, targetInst.RedistributeBGP)
|
|
|
|
|
+ }
|
|
|
|
|
+ if v, ok := params["redistribute-ospf"]; ok {
|
|
|
|
|
+ targetInst.RedistributeOSPF = parseCLIEnableDisable(v, targetInst.RedistributeOSPF)
|
|
|
|
|
+ }
|
|
|
|
|
+ if v, ok := params["redistribute-default"]; ok {
|
|
|
|
|
+ targetInst.RedistributeDefault = parseCLIEnableDisable(v, targetInst.RedistributeDefault)
|
|
|
|
|
+ }
|
|
|
|
|
+ if _, err := e.dynRoutingMgr.SaveBabelInstance(*targetInst); err != nil {
|
|
|
|
|
+ return ColorRed + "Error: " + err.Error() + "\n" + ColorReset
|
|
|
|
|
+ }
|
|
|
|
|
+ return ColorGreen + fmt.Sprintf("Babel instance %s updated.\n", targetInst.Name) + ColorReset
|
|
|
|
|
+
|
|
|
case "remove", "rem", "delete":
|
|
case "remove", "rem", "delete":
|
|
|
pos, _ := parseArgs(parts[1:])
|
|
pos, _ := parseArgs(parts[1:])
|
|
|
if len(pos) == 0 {
|
|
if len(pos) == 0 {
|
|
@@ -3600,7 +3672,7 @@ func (e *Executor) handleBabelInstance(parts []string, user *auth.PublicUser) st
|
|
|
return ColorGreen + fmt.Sprintf("Babel instance %s disabled.\n", target) + ColorReset
|
|
return ColorGreen + fmt.Sprintf("Babel instance %s disabled.\n", target) + ColorReset
|
|
|
|
|
|
|
|
default:
|
|
default:
|
|
|
- return ColorRed + "Usage: /routing babel instance [print|add|remove|enable|disable]\n" + ColorReset
|
|
|
|
|
|
|
+ return ColorRed + "Usage: /routing babel instance [print|add|set|remove|enable|disable]\n" + ColorReset
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|