bird-openwrt: update to version 0.3
[feed/routing.git] / bird-openwrt / bird6-openwrt / src / model / bgp_proto.lua
index e243fa6b96a744fe573792481c0ca8fe3d35499c..de2c4a7c1a899dc4e7523781a237e0f52a751bfa 100644 (file)
@@ -1,6 +1,5 @@
 --[[ 
 --[[ 
-Copyright (C) 2014 - Eloi Carbó Solé (GSoC2014) 
-BGP/Bird integration with OpenWRT and QMP
+Copyright (C) 2014-2017 - Eloi Carbo
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -18,45 +17,68 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 require("luci.sys")
 local http = require "luci.http"
 
 require("luci.sys")
 local http = require "luci.http"
-local uci = require "luci.model.uci"
-local uciout = uci.cursor()
+local uci = luci.model.uci.cursor()
+
+-- Repeated Strings
+local common_string = "Valid options are:<br />" .. "1. all (All the routes)<br />" .. "2. none (No routes)<br />" .. "3. filter <b>Your_Filter_Name</b> (Call a specific filter from any of the available in the filters files)"
+local imp_string = "Set if the protocol must import routes.<br />" .. common_string
+local exp_string = "Set if the protocol must export routes.<br />" .. common_string
 
 m=Map("bird6", "Bird6 BGP protocol's configuration")
 
 tab_templates = {}
 
 m=Map("bird6", "Bird6 BGP protocol's configuration")
 
 tab_templates = {}
-uciout:foreach('bird6', 'bgp_template', function (s)
+uci:foreach('bird6', 'bgp_template', function (s)
        local name = s[".name"]
        if (name ~= nil) then
                table.insert(tab_templates, name)
        end
 end)
 
        local name = s[".name"]
        if (name ~= nil) then
                table.insert(tab_templates, name)
        end
 end)
 
--- Section BGP Templates
-
+--
+-- BGP TEMPLATES
+--
 sect_templates = m:section(TypedSection, "bgp_template", "BGP Templates", "Configuration of the templates used in BGP instances.")
 sect_templates.addremove = true
 sect_templates.anonymous = false
 
 disabled = sect_templates:option(Flag, "disabled", "Disabled", "Enable/Disable BGP Protocol")
 disabled.optional=true
 sect_templates = m:section(TypedSection, "bgp_template", "BGP Templates", "Configuration of the templates used in BGP instances.")
 sect_templates.addremove = true
 sect_templates.anonymous = false
 
 disabled = sect_templates:option(Flag, "disabled", "Disabled", "Enable/Disable BGP Protocol")
 disabled.optional=true
+
+description = sect_templates:option(TextValue, "description", "Description", "Description of the current BGP instance")
+description.optional = true
+
 table = sect_templates:option(ListValue, "table", "Table", "Set the table used for BGP Routing")
 table.optional=true
 table = sect_templates:option(ListValue, "table", "Table", "Set the table used for BGP Routing")
 table.optional=true
-uciout:foreach("bird6", "table",
+uci:foreach("bird6", "table",
        function (s)
                table:value(s.name)
        end)
 table:value("")
        function (s)
                table:value(s.name)
        end)
 table:value("")
+table.default = ""
+
+igp_table = sect_templates:option(ListValue, "igp_table", "IGP Table", "Select the IGP Routing Table to use. Hint: usually the same table as BGP.")
+igp_table.optional = true
+uci:foreach("bird6", "table",
+function(s)
+    igp_table:value(s.name)
+end)
+igp_table:value("")
+igp_table.default = ""
 
 
-import = sect_templates:option(Value, "import", "Import","")
+import = sect_templates:option(Value, "import", "Import", imp_string)
 import.optional=true
 import.optional=true
-export = sect_templates:option(Value, "export", "Export", "")
+
+export = sect_templates:option(Value, "export", "Export", exp_string)
 export.optional=true
 
 source_addr = sect_templates:option(Value, "source_address", "Source Address", "Source address for BGP routing. By default uses Router ID")
 source_addr.optional = true
 
 export.optional=true
 
 source_addr = sect_templates:option(Value, "source_address", "Source Address", "Source address for BGP routing. By default uses Router ID")
 source_addr.optional = true
 
-description = sect_templates:option(TextValue, "description", "Description", "Description of the current BGP instance")
-description.optional = true
+local_address = sect_templates:option(Value, "local_address", "Local BGP address", "")
+local_address.optional = false
+
+local_as = sect_templates:option(Value, "local_as", "Local AS", "")
+local_as.optional = false
 
 next_hop_self = sect_templates:option(Flag, "next_hop_self", "Next hop self", "Avoid next hop calculation and advertise own source address as next hop")
 next_hop_self.default = nil
 
 next_hop_self = sect_templates:option(Flag, "next_hop_self", "Next hop self", "Avoid next hop calculation and advertise own source address as next hop")
 next_hop_self.default = nil
@@ -73,90 +95,121 @@ rr_client.optional = true
 rr_cluster_id = sect_templates:option(Value, "rr_cluster_id", "Route Reflector Cluster ID", "Identificator of the RR cluster. By default uses the Router ID")
 rr_cluster_id.optional = true
 
 rr_cluster_id = sect_templates:option(Value, "rr_cluster_id", "Route Reflector Cluster ID", "Identificator of the RR cluster. By default uses the Router ID")
 rr_cluster_id.optional = true
 
-import_limit = sect_templates:option(Value, "import_limit", "Routes import limit", "Specify an import route limit. By default is disabled '0'")
-import_limit.default= "0"
-import_limit.optional = true
+import_trigger = sect_templates:option(Flag, "import_trigger", "Import Limit", "Enable Routes Import limit settings")
+import_trigger.default = 0
+import_trigger.rmempty = false
+import_trigger.optional = false
+
+import_limit = sect_templates:option(Value, "import_limit", "Routes import limit", "Specify an import route limit.")
+import_limit:depends({import_trigger = "1"})
+import_limit.rmempty = true
 
 import_limit_action = sect_templates:option(ListValue, "import_limit_action", "Routes import limit action", "Action to take when import routes limit ir reached")
 
 import_limit_action = sect_templates:option(ListValue, "import_limit_action", "Routes import limit action", "Action to take when import routes limit ir reached")
+import_limit_action:depends({import_trigger = "1"})
 import_limit_action:value("warn")
 import_limit_action:value("block")
 import_limit_action:value("disable")
 import_limit_action:value("restart")
 import_limit_action.default = "warn"
 import_limit_action:value("warn")
 import_limit_action:value("block")
 import_limit_action:value("disable")
 import_limit_action:value("restart")
 import_limit_action.default = "warn"
-import_limit_action.optional = true
+import_limit_action.rmempty = true
+
+export_trigger = sect_templates:option(Flag, "export_trigger", "Export Limit", "Enable Routes Export limit settings")
+export_trigger.default = 0
+export_trigger.rmempty = false
+export_trigger.optional = false
 
 
-export_limit = sect_templates:option(Value, "export_limit", "Routes export limit", "Specify an export route limit. By default is disabled '0'")
-export_limit.default="0"
-export_limit.optional = true
+export_limit = sect_templates:option(Value, "export_limit", "Routes export limit", "Specify an export route limit.")
+export_limit:depends({export_trigger = "1"})
+export_limit.rmempty = true
 
 export_limit_action = sect_templates:option(ListValue, "export_limit_action", "Routes export limit action", "Action to take when export routes limit is reached")
 
 export_limit_action = sect_templates:option(ListValue, "export_limit_action", "Routes export limit action", "Action to take when export routes limit is reached")
+export_limit_action:depends({export_trigger = "1"})
+export_limit_action.rmempty = true
 export_limit_action:value("warn")
 export_limit_action:value("block")
 export_limit_action:value("disable")
 export_limit_action:value("restart")
 export_limit_action.default = "warn"
 export_limit_action:value("warn")
 export_limit_action:value("block")
 export_limit_action:value("disable")
 export_limit_action:value("restart")
 export_limit_action.default = "warn"
-export_limit_action.optional = true
 
 
-receive_limit = sect_templates:option(Value, "receive_limit", "Routes received limit", "Specify a received route limit. By default is disabled '0'")
-receive_limit.default="0"
-receive_limit.optional = true
+receive_trigger = sect_templates:option(Flag, "receive_trigger", "Received Limit", "Enable Routes Received Limit settings")
+receive_trigger.default = 0
+receive_trigger.rmempty = false
+receive_trigger.optional = false
+
+receive_limit = sect_templates:option(Value, "receive_limit", "Routes received limit", "Specify a received route limit.")
+receive_limit:depends({receive_trigger = "1"})
+receive_limit.rmempty = true
 
 receive_limit_action = sect_templates:option(ListValue, "receive_limit_action", "Routes received limit action", "Action to take when received routes limit is reached")
 
 receive_limit_action = sect_templates:option(ListValue, "receive_limit_action", "Routes received limit action", "Action to take when received routes limit is reached")
+receive_limit_action:depends({receive_trigger = "1"})
 receive_limit_action:value("warn")
 receive_limit_action:value("block")
 receive_limit_action:value("disable")
 receive_limit_action:value("restart")
 receive_limit_action.default = "warn"
 receive_limit_action:value("warn")
 receive_limit_action:value("block")
 receive_limit_action:value("disable")
 receive_limit_action:value("restart")
 receive_limit_action.default = "warn"
-receive_limit_action.optional = true
-
-local_address = sect_templates:option(Value, "local_address", "Local BGP address", "")
-local_address.optional=true
-local_as = sect_templates:option(Value, "local_as", "Local AS", "")
-local_as.optional=true
-
--- Section BGP Instances:
+receive_limit_action.rmempty= true
 
 
+--
+-- BGP INSTANCES
+--
 sect_instances = m:section(TypedSection, "bgp", "BGP Instances", "Configuration of the BGP protocol instances")
 sect_instances.addremove = true
 sect_instances.anonymous = false
 
 templates = sect_instances:option(ListValue, "template", "Templates", "Available BGP templates")
 sect_instances = m:section(TypedSection, "bgp", "BGP Instances", "Configuration of the BGP protocol instances")
 sect_instances.addremove = true
 sect_instances.anonymous = false
 
 templates = sect_instances:option(ListValue, "template", "Templates", "Available BGP templates")
-
-uciout:foreach("bird6", "bgp_template",
+uci:foreach("bird6", "bgp_template",
        function(s)
                templates:value(s[".name"])
        end)
 templates:value("")
        function(s)
                templates:value(s[".name"])
        end)
 templates:value("")
-neighbor_address = sect_instances:option(Value, "neighbor_address", "Neighbor IP Address", "")
-neighbor_as = sect_instances:option(Value, "neighbor_as", "Neighbor AS", "")
 
 disabled = sect_instances:option(Flag, "disabled", "Disabled", "Enable/Disable BGP Protocol")
 
 disabled = sect_instances:option(Flag, "disabled", "Disabled", "Enable/Disable BGP Protocol")
-disabled.optional=true
-disabled.default=nil
+disabled.optional = false
+disabled.rmempty = false
+disabled.default = nil
+
+description = sect_instances:option(TextValue, "description", "Description", "Description of the current BGP instance")
+description.optional = true
+
 table = sect_instances:option(ListValue, "table", "Table", "Set the table used for BGP Routing")
 table.optional=true
 table = sect_instances:option(ListValue, "table", "Table", "Set the table used for BGP Routing")
 table.optional=true
-uciout:foreach("bird6", "table",
+uci:foreach("bird6", "table",
     function (s)
     function (s)
-               table:value(s.name)
-                           end)
+        table:value(s.name)
+    end)
 table:value("")
 table:value("")
+table.default = ""
 
 
-description = sect_instances:option(TextValue, "description", "Description", "Description of the current BGP instance")
-description.optional = true
+igp_table = sect_instances:option(ListValue, "igp_table", "IGP Table", "Select the IGP Routing Table to use. Hint: usually the same table as BGP.")
+igp_table.optional = true
+uci:foreach("bird6", "table",
+function(s)
+    igp_table:value(s.name)
+end)
+igp_table:value("")
+igp_table.default = ""
 
 
-import = sect_instances:option(Value, "import", "Import","")
+import = sect_instances:option(Value, "import", "Import", imp_string)
 import.optional=true
 import.optional=true
-export = sect_instances:option(Value, "export", "Export", "")
+
+export = sect_instances:option(Value, "export", "Export", exp_string)
 export.optional=true
 
 export.optional=true
 
-source_addr = sect_instances:option(Value, "source_address", "Source Address", "Source address for BGP routing. By default uses Router ID")
-source_addr.optional = true
+source_address = sect_instances:option(Value, "source_address", "Source Address", "Source address for BGP routing. By default uses Router ID")
+source_address.optional = true
 
 local_address = sect_instances:option(Value, "local_address", "Local BGP address", "")
 local_address.optional=true
 
 local_address = sect_instances:option(Value, "local_address", "Local BGP address", "")
 local_address.optional=true
+
 local_as = sect_instances:option(Value, "local_as", "Local AS", "")
 local_as.optional=true
 
 local_as = sect_instances:option(Value, "local_as", "Local AS", "")
 local_as.optional=true
 
+neighbor_address = sect_instances:option(Value, "neighbor_address", "Neighbor IP Address", "")
+neighbor_address.optional = false
+
+neighbor_as = sect_instances:option(Value, "neighbor_as", "Neighbor AS", "")
+neighbor_as.optional = false
+
 next_hop_self = sect_instances:option(Flag, "next_hop_self", "Next hop self", "Avoid next hop calculation and advertise own source address as next hop")
 next_hop_self.default = nil
 next_hop_self.optional = true
 next_hop_self = sect_instances:option(Flag, "next_hop_self", "Next hop self", "Avoid next hop calculation and advertise own source address as next hop")
 next_hop_self.default = nil
 next_hop_self.optional = true
@@ -172,66 +225,62 @@ rr_client.optional = true
 rr_cluster_id = sect_instances:option(Value, "rr_cluster_id", "Route Reflector Cluster ID", "Identificator of the RR cluster. By default uses the Router ID")
 rr_cluster_id.optional = true
 
 rr_cluster_id = sect_instances:option(Value, "rr_cluster_id", "Route Reflector Cluster ID", "Identificator of the RR cluster. By default uses the Router ID")
 rr_cluster_id.optional = true
 
-import_limit = sect_instances:option(Value, "import_limit", "Routes import limit", "Specify an import route limit. By default is disabled '0'")
-import_limit.default="0"
-import_limit.optional = true
+import_trigger = sect_instances:option(Flag, "import_trigger", "Import Limit", "Enable Routes Import limit settings")
+import_trigger.default = 0
+import_trigger.rmempty = false
+import_trigger.optional = false
+
+import_limit = sect_instances:option(Value, "import_limit", "Routes import limit", "Specify an import route limit.")
+import_limit:depends({import_trigger = "1"})
+import_limit.rmempty = true
 
 import_limit_action = sect_instances:option(ListValue, "import_limit_action", "Routes import limit action", "Action to take when import routes limit ir reached")
 
 import_limit_action = sect_instances:option(ListValue, "import_limit_action", "Routes import limit action", "Action to take when import routes limit ir reached")
+import_limit_action:depends({import_trigger = "1"})
 import_limit_action:value("warn")
 import_limit_action:value("block")
 import_limit_action:value("disable")
 import_limit_action:value("restart")
 import_limit_action.default = "warn"
 import_limit_action:value("warn")
 import_limit_action:value("block")
 import_limit_action:value("disable")
 import_limit_action:value("restart")
 import_limit_action.default = "warn"
-import_limit_action.optional = true
+import_limit_action.rmempty = true
 
 
-export_limit = sect_instances:option(Value, "export_limit", "Routes export limit", "Specify an export route limit. By default is disabled '0'")
-export_limit.default="0"
-export_limit.optional = true
+export_trigger = sect_instances:option(Flag, "export_trigger", "Export Limit", "Enable Routes Export limit settings")
+export_trigger.default = 0
+export_trigger.rmempty = false
+export_trigger.optional = false
+
+export_limit = sect_instances:option(Value, "export_limit", "Routes export limit", "Specify an export route limit.")
+export_limit:depends({export_trigger = "1"})
+export_limit.rmempty = true
 
 export_limit_action = sect_instances:option(ListValue, "export_limit_action", "Routes export limit action", "Action to take when export routes limit is reached")
 
 export_limit_action = sect_instances:option(ListValue, "export_limit_action", "Routes export limit action", "Action to take when export routes limit is reached")
+export_limit_action:depends({export_trigger = "1"})
+export_limit_action.rmempty = true
 export_limit_action:value("warn")
 export_limit_action:value("block")
 export_limit_action:value("disable")
 export_limit_action:value("restart")
 export_limit_action.default = "warn"
 export_limit_action:value("warn")
 export_limit_action:value("block")
 export_limit_action:value("disable")
 export_limit_action:value("restart")
 export_limit_action.default = "warn"
-export_limit_action.optional = true
 
 
-receive_limit = sect_instances:option(Value, "receive_limit", "Routes received limit", "Specify a received route limit. By default is disabled '0'")
-receive_limit.default="0"
-receive_limit.optional = true
+receive_trigger = sect_instances:option(Flag, "receive_trigger", "Received Limit", "Enable Routes Received Limit settings")
+receive_trigger.default = 0
+receive_trigger.rmempty = false
+receive_trigger.optional = false
+
+receive_limit = sect_instances:option(Value, "receive_limit", "Routes received limit", "Specify a received route limit.")
+receive_limit:depends({receive_trigger = "1"})
+receive_limit.rmempty = true
 
 receive_limit_action = sect_instances:option(ListValue, "receive_limit_action", "Routes received limit action", "Action to take when received routes limit is reached")
 
 receive_limit_action = sect_instances:option(ListValue, "receive_limit_action", "Routes received limit action", "Action to take when received routes limit is reached")
+receive_limit_action:depends({receive_trigger = "1"})
 receive_limit_action:value("warn")
 receive_limit_action:value("block")
 receive_limit_action:value("disable")
 receive_limit_action:value("restart")
 receive_limit_action.default = "warn"
 receive_limit_action:value("warn")
 receive_limit_action:value("block")
 receive_limit_action:value("disable")
 receive_limit_action:value("restart")
 receive_limit_action.default = "warn"
-receive_limit_action.optional = true
-
--- Section BGP Filters
-
-sect_filters = m:section(TypedSection, "filter", "BGP Filters", "Filters of the BGP instances")
-sect_filters.addremove = true
-sect_filters.anonymous = false
-sect_filters:depends("type", "bgp")
-
-instance = sect_filters:option(ListValue, "instance", "BGP instance", "Filter's BGP instance")
-instance:depends("type", "bgp")
-
-uciout:foreach("bird6", "bgp",
-       function (s)
-               instance:value(s[".name"])
-       end)
-
-type = sect_filters:option(Value, "type", "Filter type", "")
-type.default = "bgp"
-
-path = sect_filters:option(Value, "file_path", "Filter's file path", "Path to the Filter's file")
-path:depends("type", "bgp")
+receive_limit_action.rmempty= true
 
 function m.on_commit(self,map)
 
 function m.on_commit(self,map)
-        luci.sys.call('/etc/init.d/bird6 stop; /etc/init.d/bird6 start')
+        luci.sys.exec('/etc/init.d/bird6 restart')
 end
 
 return m
 end
 
 return m
-