Skip to content

Commit

Permalink
feat: New OSPF resource
Browse files Browse the repository at this point in the history
Fixed small implementation flaws
  • Loading branch information
vaerh committed Jun 19, 2023
1 parent adca988 commit 4d473ea
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 55 deletions.
11 changes: 6 additions & 5 deletions routeros/resource_routing_ospf_area.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,28 @@ import (
func ResourceRoutingOspfArea() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/routing/ospf/area"),
MetaId: PropId(Name),
MetaId: PropId(Id),

KeyName: PropNameForceNewRw,
KeyComment: PropCommentRw,
KeyDisabled: PropDisabledRw,
"area_id": {
Type: schema.TypeString,
Default: "0.0.0.0",
Optional: true,
Description: "OSPF area identifier.",
},
KeyComment: PropCommentRw,
"default_cost": {
Type: schema.TypeInt,
Optional: true,
Description: "Default cost of injected LSAs into the area.",
},
KeyDisabled: PropDisabledRw,
KeyInactive: PropInactiveRo,
"instance": {
Type: schema.TypeString,
Required: true,
Description: "Name of the OSPF instance this area belongs to.",
},
KeyName: PropNameForceNewRw,
"no_summaries": {
Type: schema.TypeBool,
Default: false,
Expand All @@ -60,7 +61,7 @@ func ResourceRoutingOspfArea() *schema.Resource {
Optional: true,
Default: "default",
Description: "The area type.",
ValidateFunc: validation.StringInSlice([]string{"default", "nssa", "stub"}, true),
ValidateFunc: validation.StringInSlice([]string{"default", "nssa", "stub"}, false),
},
}

Expand Down
37 changes: 18 additions & 19 deletions routeros/resource_routing_ospf_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@ import (
"router-id": "",
"version": "",
"vrf": "",
"use-dn": ""
"use-dn": "" // is not present in version 7.9
}
*/

// ResourceRoutingOspfInstance https://help.mikrotik.com/docs/display/ROS/OSPF
func ResourceRoutingOspfInstance() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/routing/ospf/instance"),
MetaId: PropId(Name),
MetaId: PropId(Id),

KeyName: PropNameForceNewRw,
KeyComment: PropCommentRw,
KeyDisabled: PropDisabledRw,
"domain_id": {
Expand All @@ -46,7 +45,8 @@ func ResourceRoutingOspfInstance() *schema.Resource {
"generated by this router), and in route calculation (all external LSAs having this route " +
"tag are ignored). Needed for interoperability with older Cisco systems. By default not set.",
},
"in_filter": {
KeyInactive: PropInactiveRo,
"in_filter_chain": {
Type: schema.TypeString,
Optional: true,
Description: "name of the routing filter chain used for incoming prefixes",
Expand All @@ -61,12 +61,12 @@ func ResourceRoutingOspfInstance() *schema.Resource {
Optional: true,
Description: "the area used for MPLS traffic engineering.",
},
KeyName: PropNameForceNewRw,
"originate_default": {
Type: schema.TypeString,
Default: "never",
Optional: true,
Description: "Specifies default route (0.0.0.0/0) distribution method.",
ValidateFunc: validation.StringInSlice([]string{"always", "if-installed", "never"}, true),
ValidateFunc: validation.StringInSlice([]string{"always", "if-installed", "never"}, false),
},
"out_filter_chain": {
Type: schema.TypeString,
Expand All @@ -79,41 +79,40 @@ func ResourceRoutingOspfInstance() *schema.Resource {
Description: "name of the routing filter select chain, used for output selection.",
},
"redistribute": {
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
Description: "Enable redistribution of specific route types.",
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"bgp", "connected", "copy", "dhcp", "fantasy", "modem", "ospf", "rip", "static", "vpn"}, true),
Type: schema.TypeString,
ValidateDiagFunc: ValidationMultiValInSlice([]string{"bgp", "connected", "copy", "dhcp", "fantasy", "modem",
"ospf", "rip", "static", "vpn"}, false, false),
},
},
"router_id": {
Type: schema.TypeString,
Default: "main",
Optional: true,
Default: "main",
Description: "OSPF Router ID. Can be set explicitly as an IP address, or as the name " +
"of the router-id instance.",
},
"routing_table": {
Type: schema.TypeString,
Optional: true,
Description: "Name of the routing table in use.",
},
"version": {
Type: schema.TypeInt,
Default: 2,
Optional: true,
Default: 2,
Description: "OSPF version this instance will be running (v2 for IPv4, v3 for IPv6).",
ValidateFunc: validation.IntBetween(2, 3),
},
"vrf": {
Type: schema.TypeString,
Default: "main",
Optional: true,
Default: "main",
Description: "The VRF table this OSPF instance operates on",
},
"use_dn": {
Type: schema.TypeString,
Optional: true,
Description: "Forces to use or ignore DN bit. Useful in some CE PE scenarios to inject intra-area routes into VRF. " +
"If a parameter is unset then the DN bit is used according to RFC. Available since v6rc12.",
ValidateFunc: validation.StringInSlice([]string{"yes", "no"}, true),
},
}

return &schema.Resource{
Expand Down
70 changes: 39 additions & 31 deletions routeros/resource_routing_ospf_interface_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,6 @@ func ResourceRoutingOspfInterfaceTemplate() *schema.Resource {
MetaResourcePath: PropResourcePath("/routing/ospf/interface-template"),
MetaId: PropId(Id),

KeyComment: PropCommentRw,
KeyDisabled: PropDisabledRw,
"interfaces": {
Type: schema.TypeString,
Optional: true,
Default: "none",
Description: "Interfaces to match.",
},
"network": {
Type: schema.TypeString,
Optional: true,
Description: "The network prefix associated with the area.",
},
"area": {
Type: schema.TypeString,
Required: true,
Expand All @@ -62,15 +49,18 @@ func ResourceRoutingOspfInterfaceTemplate() *schema.Resource {
ValidateFunc: validation.StringInSlice([]string{"simple", "md5", "sha1", "sha256", "sha384", "sha512"}, true),
},
"auth_id": {
Type: schema.TypeInt,
Optional: true,
Description: "The key id is used to calculate message digest (used when MD5 or SHA authentication is enabled).",
Type: schema.TypeInt,
Optional: true,
Description: "The key id is used to calculate message digest (used when MD5 or SHA authentication is enabled).",
ValidateFunc: validation.IntBetween(0, 255),
},
"authentication_key": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
Description: "The authentication key to be used, should match on all the neighbors of the network segment.",
},
KeyComment: PropCommentRw,
"cost": {
Type: schema.TypeInt,
Optional: true,
Expand All @@ -82,17 +72,27 @@ func ResourceRoutingOspfInterfaceTemplate() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Default: "40s",
Description: "Specifies the interval after which a neighbor is declared dead.",
ValidateFunc: ValidationTime,
DiffSuppressFunc: TimeEquall,
Description: "Specifies the interval after which a neighbor is declared dead.",
},
KeyDisabled: PropDisabledRw,
"hello_interval": {
Type: schema.TypeString,
Optional: true,
Default: "10s",
Description: "The interval between HELLO packets that the router sends out this interface.",
ValidateFunc: ValidationTime,
DiffSuppressFunc: TimeEquall,
Description: "The interval between HELLO packets that the router sends out this interface.",
},
KeyInactive: PropInactiveRo,
"interfaces": {
Type: schema.TypeSet,
Optional: true,
Description: "Interfaces to match.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"instance_id": {
Type: schema.TypeInt,
Expand All @@ -101,6 +101,11 @@ func ResourceRoutingOspfInterfaceTemplate() *schema.Resource {
Default: 0,
ValidateFunc: validation.IntBetween(0, 255),
},
"network": {
Type: schema.TypeString,
Optional: true,
Description: "The network prefix associated with the area.",
},
"passive": {
Type: schema.TypeBool,
Optional: true,
Expand All @@ -123,34 +128,37 @@ func ResourceRoutingOspfInterfaceTemplate() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Default: "5s",
Description: "Time interval the lost link state advertisement will be resent.",
ValidateFunc: ValidationTime,
DiffSuppressFunc: TimeEquall,
Description: "Time interval the lost link state advertisement will be resent.",
},
"transmit_delay": {
Type: schema.TypeString,
Optional: true,
Default: "1s",
Type: schema.TypeString,
Optional: true,
Default: "1s",
Description: "Link-state transmit delay is the estimated time it takes to transmit a link-state " +
"update packet on the interface.",
ValidateFunc: ValidationTime,
DiffSuppressFunc: TimeEquall,
Description: "Link-state transmit delay is the estimated time it takes to transmit a link-state update packet on the interface.",
},
"type": {
Type: schema.TypeString,
Description: "The OSPF network type on this interface.",
Optional: true,
Default: "broadcast",
ValidateFunc: validation.StringInSlice([]string{"broadcast", "nbma", "ptp", "ptmp", "ptp-unnumbered", "virtual-link"}, true),
Type: schema.TypeString,
Description: "The OSPF network type on this interface.",
Optional: true,
Default: "broadcast",
ValidateFunc: validation.StringInSlice(
[]string{"broadcast", "nbma", "ptp", "ptmp", "ptp-unnumbered", "virtual-link"}, true),
},
"vlink_neighbor_id": {
Type: schema.TypeString,
Optional: true,
Description: "Specifies the router-id of the neighbor which should be connected over the virtual link.",
},
"vlink_transit_area": {
Type: schema.TypeString,
Optional: true,
Description: "A non-backbone area the two routers have in common over which the virtual link will be established.",
Type: schema.TypeString,
Optional: true,
Description: "A non-backbone area the two routers have in common over which the virtual link will " +
"be established.",
},
}

Expand Down

0 comments on commit 4d473ea

Please sign in to comment.