OVS bitwise port/mask ranges
Project description
# ovsportranges
### Description
Openflow requires port ranges to be defined as bitwise matches. This module
provides an easy way to the port/mask ranges for a specified port range.
As described in the [ovs-ofctl](http://www.openvswitch.org/support/dist-docs-2.5/ovs-ofctl.8.txt) documentation:
> Bitwise match on TCP (or UDP or SCTP) source or destination
> port. The port and mask are 16-bit numbers written in decimal
> or in hexadecimal prefixed by 0x. Each 1-bit in mask requires
> that the corresponding bit in port must match. Each 0-bit in
> mask causes the corresponding bit to be ignored.
It is recommended to only use this for large ranges that would require a large number of flows.
### Installation
`pip install ovsportranges`
### Basic Usage
``` python
from ovsportrange import OvsPorts
if __name__ == "__main__":
ovsports = OvsPorts()
ranges = ovsports.get_port_ranges(1000, 1999)
for r in ranges:
print("Port: {}, Bitmask: {}".format(r.port, r.bitmask))
```
### Output
```text
Port: 1000, Bitmask: 65528
Port: 1008, Bitmask: 65520
Port: 1024, Bitmask: 65024
Port: 1536, Bitmask: 65280
Port: 1792, Bitmask: 65408
Port: 1920, Bitmask: 65472
Port: 1984, Bitmask: 65520
```
### Description
Openflow requires port ranges to be defined as bitwise matches. This module
provides an easy way to the port/mask ranges for a specified port range.
As described in the [ovs-ofctl](http://www.openvswitch.org/support/dist-docs-2.5/ovs-ofctl.8.txt) documentation:
> Bitwise match on TCP (or UDP or SCTP) source or destination
> port. The port and mask are 16-bit numbers written in decimal
> or in hexadecimal prefixed by 0x. Each 1-bit in mask requires
> that the corresponding bit in port must match. Each 0-bit in
> mask causes the corresponding bit to be ignored.
It is recommended to only use this for large ranges that would require a large number of flows.
### Installation
`pip install ovsportranges`
### Basic Usage
``` python
from ovsportrange import OvsPorts
if __name__ == "__main__":
ovsports = OvsPorts()
ranges = ovsports.get_port_ranges(1000, 1999)
for r in ranges:
print("Port: {}, Bitmask: {}".format(r.port, r.bitmask))
```
### Output
```text
Port: 1000, Bitmask: 65528
Port: 1008, Bitmask: 65520
Port: 1024, Bitmask: 65024
Port: 1536, Bitmask: 65280
Port: 1792, Bitmask: 65408
Port: 1920, Bitmask: 65472
Port: 1984, Bitmask: 65520
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ovsportranges-0.1.2.tar.gz
(3.8 kB
view hashes)
Built Distribution
Close
Hashes for ovsportranges-0.1.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b2bfedf63b20200adf18f59ddd9b24bb0a2f54ecda21e47cea5d0e523506b58 |
|
MD5 | 6db416758bd825facd1dd318076e9e7e |
|
BLAKE2b-256 | 1f3b1c1c7e7b57ea1e6560100d557aaedf68f332e52586b81e882564dc2b78c1 |