Skip to content

Commit

Permalink
implement bridge domains and add support for virtual-switch (#515)
Browse files Browse the repository at this point in the history
* implement bridge domains and add support for virtual-switch

Signed-off-by: rohitthakur2590 <[email protected]>

* implement bridge domains and add support for virtual-switch

Signed-off-by: rohitthakur2590 <[email protected]>

* update docs

Signed-off-by: rohitthakur2590 <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update junos_routing_instances.py

* chore: auto fixes from pre-commit.com hooks

---------

Signed-off-by: rohitthakur2590 <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Nilashish Chakraborty <[email protected]>
  • Loading branch information
3 people authored Jun 28, 2024
1 parent fa08eab commit fc643ca
Show file tree
Hide file tree
Showing 7 changed files with 336 additions and 0 deletions.
5 changes: 5 additions & 0 deletions changelogs/fragments/implement_bridge_domains.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
minor_changes:
- Implemented bridge-domains configuration management for routing instances.
- Added support for virtual-switch instances.
- Tested successfully on Junos MX204.
189 changes: 189 additions & 0 deletions docs/junipernetworks.junos.junos_routing_instances_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,194 @@ Parameters
</tr>
<tr>
<td class="elbow-placeholder"></td>
<td colspan="2">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>bridge_domains</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">list</span>
/ <span style="color: purple">elements=dictionary</span>
</div>
</td>
<td>
</td>
<td>
<div>Bridge domain configuration.</div>
<div>This has been tested for junos MX204.</div>
</td>
</tr>
<tr>
<td class="elbow-placeholder"></td>
<td class="elbow-placeholder"></td>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>description</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">string</span>
</div>
</td>
<td>
</td>
<td>
<div>Specify domain description.</div>
</td>
</tr>
<tr>
<td class="elbow-placeholder"></td>
<td class="elbow-placeholder"></td>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>domain_id</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">integer</span>
</div>
</td>
<td>
</td>
<td>
<div>Provide the domain ID.</div>
</td>
</tr>
<tr>
<td class="elbow-placeholder"></td>
<td class="elbow-placeholder"></td>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>enable_mac_move_action</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">boolean</span>
</div>
</td>
<td>
<ul style="margin: 0; padding: 0"><b>Choices:</b>
<li>no</li>
<li>yes</li>
</ul>
</td>
<td>
<div>Enable blocking action due to mac-move in this Bridge Domain.</div>
</td>
</tr>
<tr>
<td class="elbow-placeholder"></td>
<td class="elbow-placeholder"></td>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>mcae_mac_flush</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">boolean</span>
</div>
</td>
<td>
<ul style="margin: 0; padding: 0"><b>Choices:</b>
<li>no</li>
<li>yes</li>
</ul>
</td>
<td>
<div>Enable IRB MAC synchronization in this bridge domain</div>
</td>
</tr>
<tr>
<td class="elbow-placeholder"></td>
<td class="elbow-placeholder"></td>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>name</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">string</span>
</div>
</td>
<td>
</td>
<td>
<div>Specify the name of the bridge domain.</div>
</td>
</tr>
<tr>
<td class="elbow-placeholder"></td>
<td class="elbow-placeholder"></td>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>no_irb_layer_2_copy</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">boolean</span>
</div>
</td>
<td>
<ul style="margin: 0; padding: 0"><b>Choices:</b>
<li>no</li>
<li>yes</li>
</ul>
</td>
<td>
<div>Disable transmission of layer-2 copy of packets of irb routing-interface.</div>
</td>
</tr>
<tr>
<td class="elbow-placeholder"></td>
<td class="elbow-placeholder"></td>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>no_local_switching</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">boolean</span>
</div>
</td>
<td>
<ul style="margin: 0; padding: 0"><b>Choices:</b>
<li>no</li>
<li>yes</li>
</ul>
</td>
<td>
<div>Disable local switching within CE-facing interfaces.</div>
</td>
</tr>
<tr>
<td class="elbow-placeholder"></td>
<td class="elbow-placeholder"></td>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>service_id</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">integer</span>
</div>
</td>
<td>
</td>
<td>
<div>Specify service id.</div>
</td>
</tr>
<tr>
<td class="elbow-placeholder"></td>
<td class="elbow-placeholder"></td>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>vlan_id</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">integer</span>
</div>
</td>
<td>
</td>
<td>
<div>IEEE 802.1q VLAN identifier for bridging domain (1..4094)</div>
</td>
</tr>

<tr>
<td class="elbow-placeholder"></td>
<td colspan="2">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>connector_id_advertise</b>
Expand Down Expand Up @@ -427,6 +615,7 @@ Parameters
<li>mpls-internet-multicast</li>
<li>no-forwarding</li>
<li>virtual-router</li>
<li>virtual-switch</li>
<li>vpls</li>
<li>vrf</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ def __init__(self, **kwargs):
},
"type": "list",
},
"bridge_domains": {
"elements": "dict",
"options": {
"name": {"type": "str"},
"description": {"type": "str"},
"domain_id": {"type": "int"},
"service_id": {"type": "int"},
"vlan_id": {"type": "int"},
"enable_mac_move_action": {"type": "bool"},
"mcae_mac_flush": {"type": "bool"},
"no_irb_layer_2_copy": {"type": "bool"},
"no_local_switching": {"type": "bool"},
},
"type": "list",
},
"l2vpn_id": {"type": "str"},
"name": {"type": "str"},
"no_irb_layer_2_copy": {"type": "bool"},
Expand All @@ -81,6 +96,7 @@ def __init__(self, **kwargs):
"mpls-internet-multicast",
"no-forwarding",
"virtual-router",
"virtual-switch",
"vpls",
"vrf",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,28 @@ def _state_merged(self, want, have):
)
build_child_xml_node(int_node, "name", interface["name"])

# add child node bridge-domains
if instance.get("bridge_domains"):
br_domains = instance["bridge_domains"]
for domain in br_domains:
br_domain_node = build_child_xml_node(rinst_node, "bridge-domains")
domain_node = build_child_xml_node(br_domain_node, "domain")

attributes = ["name", "description", "domain_id", "service_id", "vlan_id"]
for attr in attributes:
if domain.get(attr):
build_child_xml_node(domain_node, attr.replace("_", "-"), domain[attr])

boolean_attributes = [
"enable_mac_move_action",
"mcae_mac_flush",
"no_irb_layer_2_copy",
"no_local_switching",
]
for attr in boolean_attributes:
if domain.get(attr):
build_child_xml_node(domain_node, attr.replace("_", "-"))

# add node l2vpn-id TODO
if instance.get("l2vpn_id"):
build_child_xml_node(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,25 @@ def parse_instance(self, instance):
vrf_exp_lst.append(vrf_exp)
instance_dict["vrf_exports"] = vrf_exp_lst

# read bridge domains
if instance.get("bridge-domains"):
br_domain_lst = []
br_domains = instance.get("bridge-domains").get("domain")
if isinstance(br_domains, list):
for domain in br_domains:
br_item = {
k.replace("-", "_"): (v if v is not None else True)
for k, v in domain.items()
}
br_domain_lst.append(br_item)
else:
br_item = {
k.replace("-", "_"): (v if v is not None else True)
for k, v in br_domains.items()
}
br_domain_lst.append(br_item)
instance_dict["bridge_domains"] = br_domain_lst

return utils.remove_empties(instance_dict)

def parse_interface(self, interface):
Expand Down
35 changes: 35 additions & 0 deletions plugins/modules/junos_routing_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,40 @@
description: Primary role of L2Backhaul-vpn router.
type: str
choices: ['access', 'nni']
bridge_domains:
description:
- Bridge domain configuration.
- This has been tested for junos MX204.
type: list
elements: dict
suboptions:
name:
description: Specify the name of the bridge domain.
type: str
description:
description: Specify domain description.
type: str
domain_id:
description: Provide the domain ID.
type: int
enable_mac_move_action:
description: Enable blocking action due to mac-move in this Bridge Domain.
type: bool
vlan_id:
description: IEEE 802.1q VLAN identifier for bridging domain (1..4094)
type: int
mcae_mac_flush:
description: Enable IRB MAC synchronization in this bridge domain
type: bool
no_irb_layer_2_copy:
description: Disable transmission of layer-2 copy of packets of irb routing-interface.
type: bool
no_local_switching:
description: Disable local switching within CE-facing interfaces.
type: bool
service_id:
description: Specify service id.
type: int
type:
description: Specify instance type.
type: str
Expand All @@ -104,6 +138,7 @@
- mpls-internet-multicast
- no-forwarding
- virtual-router
- virtual-switch
- vpls
- vrf
interfaces:
Expand Down
50 changes: 50 additions & 0 deletions tests/unit/modules/network/junos/test_junos_routing_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,56 @@ def sort_routing_instances(self, entry_list):
if entry.get("instance"):
entry["routing_instances"].sort(key=lambda i: i.get("name"))

def test_junos_routing_instances_domains_merged(self):
set_module_args(
dict(
config=[
dict(
name="EVPN",
type="virtual-switch",
route_distinguisher="10.0.0.21:444",
bridge_domains=[
dict(
name="BD456",
vlan_id=456,
enable_mac_move_action=True,
mcae_mac_flush=True,
no_local_switching=True,
service_id=20,
),
dict(
name="BD457",
vlan_id=457,
),
],
),
dict(
name="mgmt_junos",
),
],
state="merged",
),
)
commands = [
'<nc:routing-instances xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">'
"<nc:instance><nc:name>EVPN</nc:name>"
"<nc:instance-type>virtual-switch</nc:instance-type>"
"<nc:bridge-domains><nc:domain>"
"<nc:name>BD456</nc:name>"
"<nc:service-id>20</nc:service-id>"
"<nc:vlan-id>456</nc:vlan-id>"
"<nc:enable-mac-move-action/>"
"<nc:mcae-mac-flush/>"
"<nc:no-local-switching/>"
"</nc:domain></nc:bridge-domains>"
"<nc:bridge-domains><nc:domain><nc:name>BD457</nc:name>"
"<nc:vlan-id>457</nc:vlan-id></nc:domain></nc:bridge-domains>"
"<nc:route-distinguisher><nc:rd-type>10.0.0.21:444</nc:rd-type></nc:route-distinguisher>"
"</nc:instance><nc:instance><nc:name>mgmt_junos</nc:name></nc:instance></nc:routing-instances>",
]
result = self.execute_module(changed=True, commands=commands)
self.assertEqual(sorted(result["commands"]), sorted(commands))

def test_junos_routing_instances_merged(self):
set_module_args(
dict(
Expand Down

0 comments on commit fc643ca

Please sign in to comment.