示例#1
0
func marshalOutput(p openflow.OutPort) ([]byte, error) {
	v := make([]byte, 16)
	binary.BigEndian.PutUint16(v[0:2], uint16(OFPAT_OUTPUT))
	binary.BigEndian.PutUint16(v[2:4], 16)

	var port uint32
	switch {
	case p.IsTable():
		port = OFPP_TABLE
	case p.IsFlood():
		port = OFPP_FLOOD
	case p.IsAll():
		port = OFPP_ALL
	case p.IsController():
		port = OFPP_CONTROLLER
	case p.IsInPort():
		port = OFPP_IN_PORT
	case p.IsNone():
		port = OFPP_ANY
	default:
		port = p.Value()
	}
	binary.BigEndian.PutUint32(v[4:8], port)
	// We don't support buffer ID and partial PACKET_IN
	binary.BigEndian.PutUint16(v[8:10], 0xFFFF)

	return v, nil
}
示例#2
0
func marshalQueue(p openflow.OutPort, queue uint32) ([]byte, error) {
	v := make([]byte, 16)
	binary.BigEndian.PutUint16(v[0:2], uint16(OFPAT_ENQUEUE))
	binary.BigEndian.PutUint16(v[2:4], 16)

	var port uint16
	switch {
	case p.IsTable():
		port = OFPP_TABLE
	case p.IsFlood():
		port = OFPP_FLOOD
	case p.IsAll():
		port = OFPP_ALL
	case p.IsController():
		port = OFPP_CONTROLLER
	case p.IsNone():
		port = OFPP_NONE
	default:
		port = uint16(p.Value())
	}
	binary.BigEndian.PutUint16(v[4:6], port)
	// v[6:12] is padding
	binary.BigEndian.PutUint32(v[12:16], queue)

	return v, nil
}