Files
Xen-Orchestra-xen-orchestra…/@xen-orchestra/openflow
Bastien Nollet b96a6dc1e9 feat: technical release (#10022)
* feat(@xen-orchestra/fs): 4.9.1

* feat(@vates/generator-toolbox): 1.1.3

* feat(@xen-orchestra/disk-transform): 1.3.1

* feat(@vates/fuse-vhd): 2.1.3

* feat(xo-common): 0.10.0

* feat(xen-api): 4.7.8

* feat(@vates/types): 1.27.0

* feat(@xen-orchestra/acl): 1.3.0

* feat(@xen-orchestra/backup-archive): 1.0.2

* feat(@xen-orchestra/qcow2): 1.3.1

* feat(@xen-orchestra/xapi): 8.9.0

* feat(@xen-orchestra/backups): 0.73.3

* feat(@xen-orchestra/disk-cli): 2.1.2

* feat(@xen-orchestra/web-core): 0.55.0

* feat(@xen-orchestra/mcp): 1.4.1

* feat(@xen-orchestra/mixins): 0.20.1

* feat(@xen-orchestra/openflow): 0.1.4

* feat(@xen-orchestra/proxy): 0.30.4

* feat(@xen-orchestra/qa-test): 1.1.0

* feat(@xen-orchestra/rest-api): 0.34.0

* feat(@xen-orchestra/upload-ova): 0.1.8

* feat(@xen-orchestra/web): 0.54.0

* feat(xo-acl-resolver): 0.5.3

* feat(xo-server): 5.203.0

* feat(xo-server-audit): 0.15.1

* feat(xo-server-ipmi-sensors): 2.0.1

* feat(xo-server-load-balancer): 0.13.0

* feat(xo-server-netbox): 1.13.0

* feat(xo-server-openmetrics): 1.7.0

* feat(xo-server-sdn-controller): 1.3.3

* feat(xo-web): 5.198.0

* chore(CHANGELOG): update next
2026-06-24 10:18:29 +02:00
..
2022-02-18 17:11:52 +01:00
2026-06-24 10:18:29 +02:00
2023-02-06 11:25:12 +01:00

@xen-orchestra/openflow

Package Version License PackagePhobia Node compatibility

Pack and unpack OpenFlow messages

Install

Installation of the npm package:

npm install --save @xen-orchestra/openflow

Usage

Unpacking a received OpenFlow message from a socket:

import openflow from '@xen-orchestra/openflow'
import parse from '@xen-orchestra/openflow/parse-socket'

const version = openflow.versions.openFlow11
const ofProtocol = openflow.protocols[version]

function parseOpenFlowMessages(socket) {
  for await (const msg of parse(socket)) {
    if (msg.header !== undefined) {
      const ofType = msg.header.type
      switch (ofType) {
        case ofProtocol.type.hello:
          // Handle OFPT_HELLO
          break
        case ofProtocol.type.error:
          // Handle OFPT_ERROR
          break
        case ofProtocol.type.echoRequest:
          // Handle OFPT_ECHO_REQUEST
          break
        case ofProtocol.type.packetIn:
          // Handle OFPT_PACKET_IN
          break
        case ofProtocol.type.featuresReply:
          // Handle OFPT_FEATURES_REPLY
          break
        case ofProtocol.type.getConfigReply:
          // Handle OFPT_GET_CONFIG_REPLY
          break
        case ofProtocol.type.portStatus:
          // Handle OFPT_PORT_STATUS
          break
        case ofProtocol.type.flowRemoved:
          // Handle OFPT_FLOW_REMOVED
          break
        default:
          // Error: Invalid type
          break
      }
    } else {
      // Error: Message is unparseable
    }
  }
}

Unpacking a OpenFlow message from a buffer:

import openflow from '@xen-orchestra/openflow'

const version = openflow.versions.openFlow11
const ofProtocol = openflow.protocols[version]

function processOpenFlowMessage(buf) {
  const unpacked = openflow.unpack(buf)
  const ofType = unpacked.header.type
  switch (ofType) {
    case ofProtocol.type.hello:
      // Handle OFPT_HELLO
      break
    case ofProtocol.type.error:
      // Handle OFPT_ERROR
      break
    case ofProtocol.type.echoRequest:
      // Handle OFPT_ECHO_REQUEST
      break
    case ofProtocol.type.packetIn:
      // Handle OFPT_PACKET_IN
      break
    case ofProtocol.type.featuresReply:
      // Handle OFPT_FEATURES_REPLY
      break
    case ofProtocol.type.getConfigReply:
      // Handle OFPT_GET_CONFIG_REPLY
      break
    case ofProtocol.type.portStatus:
      // Handle OFPT_PORT_STATUS
      break
    case ofProtocol.type.flowRemoved:
      // Handle OFPT_FLOW_REMOVED
      break
    default:
      // Error: Invalid type
      break
  }
}

Packing an OpenFlow OFPT_HELLO message:

import openflow from '@xen-orchestra/openflow'

const version = openflow.versions.openFlow11
const ofProtocol = openflow.protocols[version]

const buf = openflow.pack({
  header: {
    version,
    type: ofProtocol.type.hello,
    xid: 1,
  },
})

Contributions

Contributions are very welcomed, either on the documentation or on the code.

You may:

  • report any issue you've encountered;
  • fork and create a pull request.

License

ISC © Vates SAS