In [2]:
import zof.codec
Let's test zof.codec to make sure it is working.
In [3]:
'type: FEATURES_REQUEST'.encode('openflow')
Out[3]:
The output shows a binary OpenFlow version 1.3 (0x04) message. We can decode this using decode.
In [4]:
print(b'\x04\x05\x00\x08\x00\x00\x00\x00'.decode('openflow'))
In [5]:
import zof.codec
def dump(s):
try:
print(s.encode('openflow').decode('openflow'))
except Exception as ex:
print(ex)
dump('''
type: HELLO
version: 1
''')
In [6]:
dump('''
type: FLOW_MOD
msg:
command: ADD
table_id: 0
buffer_id: 7
match:
- field: ETH_DST
value: 00:00:00:00:00:01
''')
In [7]:
dump('''
type: ROLE_request
msg:
role: ROLE_MASTER
generation_id: 0x10
''')
In [8]:
dump('''
type: ROLE_REQUEST
msg:
role: ROLE_MASTER
generation: 0x10
''')
In [9]:
dump('''
type: ROLE_REQUEST
msg:
role: ROLE_MASTER
generation_id: 0x10
extra: 1
''')
In [10]:
dump('''
type: ROLE_REQUEST
msg:
role: 1000
generation_id: 0x10
extra: 1
''')
In [11]:
dump('''
{
"type": "ROLE_REQUEST",
"msg": {
role: ROLE_MASTER,
generation_id: "0x10"
}
}
''')
In [ ]: