Skip to content

Commit

Permalink
Fix interface mapping (#3)
Browse files Browse the repository at this point in the history
* Fix node mapping and package meta data

- fix longest prefix node type mapping
- update package meta data
- added a note regarding configurations when changing node Types

* dependency update

* Fix slot calculation

- fix slot calculation to use correct id and slot
- update documentation
- add section about manual node configuration changes to the README

* add more files to ignore

* do not run tests on pr
  • Loading branch information
rschmied authored Apr 25, 2024
1 parent 5cbc5c0 commit e5eaabf
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ name: Python package
on:
push:
branches: [ "main", "dev" ]
pull_request:
branches: [ "main" ]
# pull_request:
# branches: [ "main" ]

jobs:
build:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,7 @@ cython_debug/
UNLs/
ZIPs/
assets/header.xcf

.DS_Store
*.yaml
*.unl
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

- v0.1.0b4
- fix slot calculation
- added a section about manual node configuration changes to the README
- more diagnostic output at debug log level
- v0.1.0b3
- fix longest prefix node type mapping
- update package meta data
Expand Down
45 changes: 44 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ After modification / adding more or different node type mappings to the exported
Disclaimer: There's certainly things out there which do not properly translate. If you encounter anything then raise an issue in the issue tracker and I'll look into it.

> [!NOTE]
> It is possible to change node types when importing. For example, you might want to change IOSv-L2 instances to IOLL2-XE instances by providing a custom import map. Note, however, that this does **NOT** change the device configuration of the imported nodes. So, if the configuration uses `GigabitEthernet0/4` in the original IOSv-L2 configuration then it is your responsibility to change this to `Ethernet1/0` for the configuration of the imported IOLL2-XE device. This can be easily done via a sed script or using a text editor and global search and replace. However, this might be more involved depending on the original/target device type.
> It is possible to change node types when importing. For example, you might want to change IOSv-L2 instances to IOLL2-XE instances by providing a custom import map. However, this does **NOT** change the device configuration of the imported nodes. So, if the configuration uses `GigabitEthernet0/4` in the original IOSv-L2 configuration then it is your responsibility to change this to `Ethernet1/0` for the configuration of the imported IOLL2-XE device. This can be easily done via a sed script or using a text editor and global search and replace. But this might be more involved depending on the original/target device type. See the "Change configurations" section below for an example.
### Usage

Expand Down Expand Up @@ -62,6 +62,49 @@ Example: eve2cml exportedlabs.zip
$
```
### Change configurations

With a custom mapper file, node types can be modified while importing. For example, adding map entries like the following

```yaml
qemu:vios:
image_def: null
node_def: iol-xe
override: false
qemu:viosl2:
image_def: null
node_def: ioll2-xe
override: false
```
to the mapper will change all IOSv instances to IOL-XE instances and all IOSv-L2 instances to IOLL2-XE instances. However, the day zero configuration files of those nodes will not be modified to match the now different interface names. In this particular case, where most of the configuration between IOSv and IOL-XE is identical *except for the interface names*, a simple sed script can do the trick. Here's how this can be done:
1. create a sed script file with this content, filename `ios2iol-config`:
```plain
s#GigabitEthernet0/0#Ethernet0/0#
s#GigabitEthernet0/1#Ethernet0/1#
s#GigabitEthernet0/2#Ethernet0/2#
s#GigabitEthernet0/3#Ethernet0/3#
s#GigabitEthernet0/4#Ethernet1/0#
s#GigabitEthernet0/5#Ethernet1/1#
s#GigabitEthernet0/6#Ethernet1/2#
s#GigabitEthernet0/7#Ethernet1/3#
s#GigabitEthernet0/8#Ethernet2/0#
s#GigabitEthernet0/9#Ethernet2/1#
s#GigabitEthernet0/10#Ethernet2/2#
s#GigabitEthernet0/11#Ethernet2/3#
s#GigabitEthernet0/12#Ethernet3/0#
s#GigabitEthernet0/13#Ethernet3/1#
s#GigabitEthernet0/14#Ethernet3/2#
s#GigabitEthernet0/15#Ethernet3/3#
```
2. dump the default / built-in mapper into a file (`--dump` option)
3. modify the mapper to include the changes outlined above
2. convert the topology with the modified map file (`--mapper` option)
3. run `sed -f ios2iol-config lab.yaml >lab_with_configs_changed.yaml`

This will change all occurrences within the CML lab file from IOSv notation to IOL notation.

### Contributing

If you have a more complete map file with additional or more specific node type mappings or if you have improved the code, fixed a bug or a typo or added a new feature then I more than welcome you to raise a pull request!
Expand Down
2 changes: 1 addition & 1 deletion src/eve2cml/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.0b3"
__version__ = "0.1.0b4"
7 changes: 5 additions & 2 deletions src/eve2cml/eve/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ def __repr__(self):
return f"{self.__class__.__name__}(id={self.id}, slot={self.slot})"

def as_cml_dict(self, idx, node_def, lab):
# can likely remove the idx arg as the id should match the idx!
assert self.id == idx
return {
# "id": f"i{self.id}",
"id": f"i{idx}",
"label": lab.mapper.cml_iface_label(self.slot, node_def, self.name),
"slot": self.slot,
Expand All @@ -57,7 +60,7 @@ def parse(
no_iol = obj_type != "iol"

interfaces: List[Interface] = []
for idx, interface_elem in enumerate(elem):
for interface_elem in elem:
id = int(interface_elem.attrib.get("id", "unknown"))
interface = Interface(
id=id,
Expand All @@ -71,7 +74,7 @@ def parse(
srcpos=interface_elem.attrib.get("srcpos", ""),
dstpos=interface_elem.attrib.get("dstpos", ""),
node_id=node_id,
slot=idx if no_iol else ((id & 0xF) * 4) + (id >> 4),
slot=id if no_iol else ((id & 0xF) * 4) + (id >> 4),
)
interfaces.append(interface)
return interfaces
20 changes: 14 additions & 6 deletions src/eve2cml/eve/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,32 @@ def as_cml_dict(self, node_id: int, lab: "Lab"):
nd_map = lab.mapper.node_def(self.obj_type, self.template, self.image)

temp_list: List[Interface] = []
prev = 0
prev_idx = 0
prev_slot = 0
_LOGGER.debug(self.interfaces)
for idx, iface in enumerate(self.interfaces):
delta = iface.slot - prev
delta = iface.slot - prev_slot
_LOGGER.debug(
"idx, slot, prev, delta %d/%d/%d/%d", idx, iface.slot, prev, delta
"idx, slot, prev, delta %d/%d/%d/%d", idx, iface.slot, prev_slot, delta
)
for idx2 in range(delta):
_LOGGER.debug(
"prepending filler interface id %d/%d", prev_idx, prev_slot + idx2
)
temp_list.append(
Interface(
id=idx + idx2,
id=prev_idx,
obj_type=self.obj_type,
network_id=999999,
name="filler",
slot=prev + idx2,
slot=prev_slot + idx2,
)
)
prev_idx += 1
iface.id = prev_idx
temp_list.append(iface)
prev = iface.slot + 1
prev_slot = iface.slot + 1
prev_idx += 1

_LOGGER.debug("list %s", temp_list)

Expand Down

0 comments on commit e5eaabf

Please sign in to comment.