Skip to content
Permalink
Browse files

devel ext244 for ofdpa (#125)

* cofaction.h => revised cofaction_set_field for EXT-244

* cofaction.h => cofaction_set_field: add support for coxmatch_packet_register according to EXT-244 with zero oxm body
  • Loading branch information...
akoepsel committed Oct 24, 2019
1 parent af2571e commit 81f6ab0cfea15f16627aa8659e784c709e57ebea
@@ -1784,6 +1784,9 @@ void cofaction_set_field::pack(uint8_t *buf, size_t buflen) {
(struct rofl::openflow13::ofp_action_set_field *)buf;

switch (oxm_set_field_type) {
case OXM_TYPE_UNKNOWN: {
oxm.pack(hdr->field, oxm.length());
} break;
case OXM_TYPE_8: {
oxm_8.pack(hdr->field, oxm_8.length());
} break;
@@ -1855,8 +1858,12 @@ void cofaction_set_field::unpack(uint8_t *buf, size_t buflen) {
if (oxm_hdr->oxm_field & 0x01 /*has_mask?*/) {

switch (be16toh(oxm_hdr->oxm_class)) {
case rofl::openflow::OFPXMC_OPENFLOW_BASIC: {
case rofl::openflow::OFPXMC_OPENFLOW_BASIC:
case rofl::openflow::OFPXMC_PACKET_REGS: {
switch (oxm_hdr->oxm_length) {
case 0 /*bytes*/: {
set_oxm().unpack(hdr->field, oxm_len);
} break;
case 2 /*bytes*/: {
set_oxm_8().unpack(hdr->field, oxm_len);
} break;
@@ -1892,8 +1899,12 @@ void cofaction_set_field::unpack(uint8_t *buf, size_t buflen) {
} else {

switch (be16toh(oxm_hdr->oxm_class)) {
case rofl::openflow::OFPXMC_OPENFLOW_BASIC: {
case rofl::openflow::OFPXMC_OPENFLOW_BASIC:
case rofl::openflow::OFPXMC_PACKET_REGS: {
switch (oxm_hdr->oxm_length) {
case 0 /*byte*/: {
set_oxm().unpack(hdr->field, oxm_len);
} break;
case 1 /*byte*/: {
set_oxm_8().unpack(hdr->field, oxm_len);
} break;
@@ -1969,8 +1969,8 @@ class cofaction_set_field : public cofaction {
*/
cofaction_set_field(uint8_t ofp_version = rofl::openflow::OFP_VERSION_UNKNOWN)
: cofaction(ofp_version, rofl::openflow::OFPAT_SET_FIELD),
oxm_set_field_type(OXM_TYPE_UNKNOWN), oxm_8(0), oxm_16(0), oxm_24(0),
oxm_32(0), oxm_48(0), oxm_64(0), oxm_128(0){};
oxm_set_field_type(OXM_TYPE_UNKNOWN), oxm(0), oxm_8(0), oxm_16(0),
oxm_24(0), oxm_32(0), oxm_48(0), oxm_64(0), oxm_128(0){};

/**
*
@@ -1981,8 +1981,8 @@ class cofaction_set_field : public cofaction {
*
*/
cofaction_set_field(const cofaction_set_field &action)
: oxm_set_field_type(OXM_TYPE_UNKNOWN), oxm_8(0), oxm_16(0), oxm_24(0),
oxm_32(0), oxm_48(0), oxm_64(0), oxm_128(0) {
: oxm_set_field_type(OXM_TYPE_UNKNOWN), oxm(0), oxm_8(0), oxm_16(0),
oxm_24(0), oxm_32(0), oxm_48(0), oxm_64(0), oxm_128(0) {
*this = action;
};

@@ -1994,6 +1994,7 @@ class cofaction_set_field : public cofaction {
return *this;
cofaction::operator=(action);
oxm_set_field_type = action.oxm_set_field_type;
oxm = action.oxm;
oxm_8 = action.oxm_8;
oxm_16 = action.oxm_16;
oxm_24 = action.oxm_24;
@@ -2018,6 +2019,9 @@ class cofaction_set_field : public cofaction {
*/
uint16_t get_oxm_class() const {
switch (oxm_set_field_type) {
case OXM_TYPE_UNKNOWN: {
return oxm.get_oxm_class();
} break;
case OXM_TYPE_8: {
return oxm_8.get_oxm_class();
} break;
@@ -2053,6 +2057,9 @@ class cofaction_set_field : public cofaction {
*/
uint8_t get_oxm_field() const {
switch (oxm_set_field_type) {
case OXM_TYPE_UNKNOWN: {
return oxm.get_oxm_field();
} break;
case OXM_TYPE_8: {
return oxm_8.get_oxm_field();
} break;
@@ -2088,6 +2095,9 @@ class cofaction_set_field : public cofaction {
*/
uint32_t get_oxm_type() const {
switch (oxm_set_field_type) {
case OXM_TYPE_UNKNOWN: {
return oxm.get_oxm_type();
} break;
case OXM_TYPE_8: {
return oxm_8.get_oxm_type();
} break;
@@ -2123,6 +2133,9 @@ class cofaction_set_field : public cofaction {
*/
uint32_t get_oxm_id() const {
switch (oxm_set_field_type) {
case OXM_TYPE_UNKNOWN: {
return oxm.get_oxm_id();
} break;
case OXM_TYPE_8: {
return oxm_8.get_oxm_id();
} break;
@@ -2167,6 +2180,29 @@ class cofaction_set_field : public cofaction {
}
};

public:
/**
*
*/
const rofl::openflow::coxmatch &get_oxm() const { return oxm; };

/**
*
*/
rofl::openflow::coxmatch &set_oxm() {
oxm_set_field_type = OXM_TYPE_UNKNOWN;
return oxm;
};

/**
*
*/
cofaction_set_field &set_oxm(const rofl::openflow::coxmatch &oxm) {
oxm_set_field_type = OXM_TYPE_UNKNOWN;
this->oxm = oxm;
return *this;
};

public:
/**
*
@@ -2374,6 +2410,9 @@ class cofaction_set_field : public cofaction {

os << dynamic_cast<const cofaction &>(action);
switch (action.get_oxm_set_field_type()) {
case OXM_TYPE_UNKNOWN: {
os << action.get_oxm();
} break;
case OXM_TYPE_8: {
os << action.get_oxm_8();
} break;
@@ -2407,6 +2446,7 @@ class cofaction_set_field : public cofaction {
private:
enum oxm_set_field_type_t oxm_set_field_type;

rofl::openflow::coxmatch oxm;
rofl::openflow::coxmatch_8 oxm_8;
rofl::openflow::coxmatch_16 oxm_16;
rofl::openflow::coxmatch_24 oxm_24;
@@ -8,11 +8,14 @@ namespace openflow {
namespace extensions {
namespace ext244 {

#define OXM_TLV_PKTREG_ID_ONLY(n) \
((uint32_t)(rofl::openflow::OFPXMC_PACKET_REGS << 16) | (n << 9))
#define OXM_TLV_PKTREG(n) \
((uint32_t)(OFPXMC_PACKET_REGS << 16) | (n << 9) | sizeof(uint64_t))
((uint32_t)(rofl::openflow::OFPXMC_PACKET_REGS << 16) | (n << 9) | \
sizeof(uint64_t))
#define OXM_TLV_PKTREG_MASK(n) \
((uint32_t)(OFPXMC_PACKET_REGS << 16) | (n << 9) | HAS_MASK_FLAG | \
2 * sizeof(uint64_t))
((uint32_t)(rofl::openflow::OFPXMC_PACKET_REGS << 16) | (n << 9) | \
HAS_MASK_FLAG | 2 * sizeof(uint64_t))

/**
* @brief OXM_OF_EXT244
@@ -1089,7 +1089,7 @@ void cofaction_test::testActionSetQueue() {
CPPUNIT_ASSERT(clone.get_queue_id() == queue_id);
}

void cofaction_test::testActionSetField() {
void cofaction_test::testActionSetField1() {
rofl::openflow::coxmatch_ofb_eth_src oxm(
rofl::caddress_ll("a1:a2:a3:a4:a5:a6"));

@@ -1131,6 +1131,49 @@ void cofaction_test::testActionSetField() {
CPPUNIT_ASSERT(clone.get_oxm_48() == oxm);
}

void cofaction_test::testActionSetField2() {
rofl::openflow::coxmatch oxm(OXM_TLV_PKTREG_ID_ONLY(17));

size_t total_length = sizeof(struct rofl::openflow13::ofp_action_set_field) -
4 * sizeof(uint8_t) + oxm.length();
size_t pad = (0x7 & total_length);
/* append padding if not a multiple of 8 */
if (pad) {
total_length += 8 - pad;
}

rofl::openflow::cofaction_set_field action;
CPPUNIT_ASSERT(rofl::openflow::OFP_VERSION_UNKNOWN == action.get_version());

action.set_version(rofl::openflow13::OFP_VERSION);
action.set_oxm(oxm);

rofl::cmemory packed(action.length());
action.pack(packed.somem(), packed.length());

std::cerr << "action:" << std::endl << action;

std::cerr << "packed:" << std::endl << packed;

CPPUNIT_ASSERT(action.get_type() == rofl::openflow::OFPAT_SET_FIELD);
CPPUNIT_ASSERT(action.get_length() == total_length);
CPPUNIT_ASSERT(action.length() == total_length);
CPPUNIT_ASSERT(action.get_oxm() == oxm);

rofl::openflow::cofaction_set_field clone(rofl::openflow13::OFP_VERSION);

clone.unpack(packed.somem(), packed.length());

std::cerr << "clone:" << std::endl << clone;

CPPUNIT_ASSERT(clone.get_type() == rofl::openflow::OFPAT_SET_FIELD);
CPPUNIT_ASSERT(clone.get_length() == total_length);
CPPUNIT_ASSERT(clone.length() == total_length);
std::cerr << ">>> oxm: <<<" << std::endl << oxm;
std::cerr << ">>> clone.oxm: <<<" << std::endl << clone.get_oxm();
CPPUNIT_ASSERT(clone.get_oxm() == oxm);
}

void cofaction_test::testActionExperimenter() {
uint32_t exp_id = 0xa1a2a3a4;
unsigned int exp_body_len = 12;
@@ -2,6 +2,7 @@
#include "rofl/common/cmemory.h"
#include "rofl/common/openflow/cofaction.h"
#include "rofl/common/openflow/experimental/actions/ext320_actions.h"
#include "rofl/common/openflow/extensions/matches/ext244_matches.h"
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>

@@ -35,7 +36,8 @@ class cofaction_test : public CppUnit::TestFixture {
CPPUNIT_TEST(testActionSetNwTtl);
CPPUNIT_TEST(testActionDecNwTtl);
CPPUNIT_TEST(testActionSetQueue);
CPPUNIT_TEST(testActionSetField);
CPPUNIT_TEST(testActionSetField1);
CPPUNIT_TEST(testActionSetField2);
CPPUNIT_TEST(testActionExperimenter);
CPPUNIT_TEST(testActionPushPbb);
CPPUNIT_TEST(testActionPopPbb);
@@ -77,7 +79,8 @@ class cofaction_test : public CppUnit::TestFixture {
void testActionSetNwTtl();
void testActionDecNwTtl();
void testActionSetQueue();
void testActionSetField();
void testActionSetField1();
void testActionSetField2();
void testActionExperimenter();
void testActionPushPbb();
void testActionPopPbb();

0 comments on commit 81f6ab0

Please sign in to comment.
You can’t perform that action at this time.