Skip to content

Commit

Permalink
Merge pull request #150 from kytos-ng/pipeline_installation
Browse files Browse the repository at this point in the history
Added new keys to flow
  • Loading branch information
viniarck authored May 11, 2023
2 parents af7f8c9 + 158be67 commit 732081f
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Added
=====

- Added support for VLAN with mask. ``dl_vlan`` now also supports a string ``"vlan/mask"``.
- Added two new fields to the collection ``flows``. ``owner`` has the name of the NApp that created the flow. ``table_group`` is the classification of a flow, for example: ``epl``, ``base`` and ``evpl``.
- Added new script ``pipeline_related.py`` to add new fields ``owner`` and ``table_group`` to the flows on the collection ``flows`` on MongoDB

Changed
=======
Expand Down
2 changes: 2 additions & 0 deletions db/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class FlowSubDoc(BaseModel):
"""Flow DB SubDocument Model."""

table_id = 0
owner: Optional[str]
table_group = "base"
priority = 0x8000
cookie: Decimal128 = Decimal128("0")
idle_timeout = 0
Expand Down
13 changes: 13 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,16 @@ And then, to insert (or update) the flows:
```
CMD=insert_flows python3 scripts/storehouse_to_mongo.py
```

### Add `owner` and `table_group` fields to `flows` collections

### Pre-requisites
Same requisites as above

### How to use

Run the script to upgrade all flows from `mef_eline`, `of_lldp` and `coloring` with new fields `owner` and `table_group`

```
python3 pipeline_related.py
```
86 changes: 86 additions & 0 deletions scripts/pipeline_related.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from kytos.core.db import mongo_client
from bson.decimal128 import Decimal128
from decimal import Decimal


client = mongo_client()
collection = client["napps"]["flows"]

# Flows from mef_eline, table groups available: epl, evpl
query_match = {
"flow.cookie": {
"$gte": Decimal128(Decimal(12249790986447749120)),
"$lte": Decimal128(Decimal(12321848580485677055)),
},
"flow.match.dl_vlan": {
"$ne": None,
}
}
update = {
"$set": {
"flow.owner": "mef_eline",
"flow.table_group": "evpl"
}
}
flows = collection.update_many(query_match, update)
print(f"{flows.modified_count} mef_eline flows were modified as EVPL.")

query_match = {
"flow.cookie": {
"$gte": Decimal128(Decimal(12249790986447749120)),
"$lte": Decimal128(Decimal(12321848580485677055)),
},
"flow.match.dl_vlan": {
"$eq": None,
}
}
update = {
"$set": {
"flow.owner": "mef_eline",
"flow.table_group": "epl"
}
}
flows = collection.update_many(query_match, update)
print(f"{flows.modified_count} mef_eline flows were modified as EPL")

# Flows from of_lldp
query_match = {
"flow.cookie": {
"$gte": Decimal128(Decimal(12321848580485677056)),
"$lte": Decimal128(Decimal(12393906174523604991)),
}
}
update = {
"$set": {
"flow.owner": "of_lldp",
"flow.table_group": "base"
}
}
flows = collection.update_many(query_match, update)
print(f"{flows.modified_count} of_lldp flows were modified as base")

# Flows from coloring
query_match = {
"flow.cookie": {
"$gte": Decimal128(Decimal(12393906174523604992)),
"$lte": Decimal128(Decimal(12465963768561532927)),
}
}
update = {
"$set": {
"flow.owner": "coloring",
"flow.table_group": "base"
}
}
flows = collection.update_many(query_match, update)
print(f"{flows.modified_count} coloring flows were modified as base")

#Any other flow with cookie 0
query_match = {
"flow.cookie": {"$eq": Decimal128(Decimal(0))}
}
update = {
"$set": {"flow.table_group": "base"}
}
flows = collection.update_many(query_match, update)
print(f"{flows.modified_count} flows were modified as base")

0 comments on commit 732081f

Please sign in to comment.