OpenFlow version independent classes and functions

Base class for OpenFlow messages

class os_ken.ofproto.ofproto_parser.MsgBase(datapath)

This is a base class for OpenFlow message classes.

An instance of this class has at least the following attributes.

Attribute

Description

datapath

A os_ken.controller.controller.Datapath instance for this message

version

OpenFlow protocol version

msg_type

Type of OpenFlow message

msg_len

Length of the message

xid

Transaction id

buf

Raw data

_TYPE

_TYPE class attribute is used to annotate types of attributes.

This type information is used to find an appropriate conversion for a JSON style dictionary.

Currently the following types are implemented.

Type

Descrption

ascii

US-ASCII

utf-8

UTF-8

Example:

_TYPE = {
    'ascii': [
        'hw_addr',
    ],
    'utf-8': [
        'name',
    ]
}
classmethod from_jsondict(dict_, decode_string=<function b64decode>, **additional_args)

Create an instance from a JSON style dict.

Instantiate this class with parameters specified by the dict.

This method takes the following arguments.

Argument

Descrpition

dict_

A dictionary which describes the parameters. For example, {"Param1": 100, "Param2": 200}

decode_string

(Optional) specify how to decode strings. The default is base64. This argument is used only for attributes which don't have explicit type annotations in _TYPE class attribute.

additional_args

(Optional) Additional kwargs for constructor.

to_jsondict(encode_string=<function b64encode>)

This method returns a JSON style dict to describe this object.

The returned dict is compatible with json.dumps() and json.loads().

Suppose ClassName object inherits StringifyMixin. For an object like the following:

ClassName(Param1=100, Param2=200)

this method would produce:

{ "ClassName": {"Param1": 100, "Param2": 200} }

This method takes the following arguments.

Argument

Description

encode_string

(Optional) specify how to encode attributes which has python 'str' type. The default is base64. This argument is used only for attributes which don't have explicit type annotations in _TYPE class attribute.

Functions

os_ken.ofproto.ofproto_parser.ofp_msg_from_jsondict(dp, jsondict)

This function instanticates an appropriate OpenFlow message class from the given JSON style dictionary. The objects created by following two code fragments are equivalent.

Code A:

jsonstr = '{ "OFPSetConfig": { "flags": 0, "miss_send_len": 128 } }'
jsondict = json.loads(jsonstr)
o = ofp_msg_from_jsondict(dp, jsondict)

Code B:

o = dp.ofproto_parser.OFPSetConfig(flags=0, miss_send_len=128)

This function takes the following arguments.

Argument

Description

dp

An instance of os_ken.controller.Datapath.

jsondict

A JSON style dict.