TEST(tabledesc, test) { TableDescBuilder tableBuilder; tableBuilder.setTableId(0x11); tableBuilder.setConfig(kFakeFlags); TableModPropertyEviction eviction; eviction.setFlags(0x31323334); TableModPropertyVacancy vacancy; vacancy.setVacancyDown(0x41); vacancy.setVacancyUp(0x51); vacancy.setVacancy(0x61); PropertyList properties; properties.add(eviction); properties.add(vacancy); tableBuilder.setProperties(properties); MemoryChannel channel{OFP_VERSION_5}; tableBuilder.write(&channel); channel.flush(); EXPECT_HEX("001811002122232400020008313233340003000841516100", channel.data(), channel.size()); }
TEST(setasync, builder) { PropertyList props; props.add(AsyncConfigPropertyPacketInSlave{kPacketInFlags}); props.add(AsyncConfigPropertyPacketInMaster{kPacketInFlags}); props.add(AsyncConfigPropertyPortStatusSlave{kPortStatusFlags}); props.add(AsyncConfigPropertyPortStatusMaster{kPortStatusFlags}); props.add(AsyncConfigPropertyFlowRemovedSlave{kFlowRemovedFlags}); props.add(AsyncConfigPropertyFlowRemovedMaster{kFlowRemovedFlags}); SetAsyncBuilder builder; builder.setProperties(props); { MemoryChannel channel{OFP_VERSION_5}; builder.send(&channel); EXPECT_HEX( "051C003800000001000000081111111200010008111111120002000822222221000300" "082222222100040008333333310005000833333331", channel.data(), channel.size()); } { MemoryChannel channel{OFP_VERSION_4}; builder.send(&channel); EXPECT_HEX( "041C002000000001111111121111111222222221222222213333333133333331", channel.data(), channel.size()); } }
// Example: /category/command?arg1=value&arg2=value bool IseServerInspector::parseCommandUrl(const HttpRequest& request, string& category, string& command, PropertyList& argList) { bool result = false; string url = request.getUrl(); string argStr; StrList strList; if (!url.empty() && url[0] == '/') url.erase(0, 1); // find the splitter char ('?') string::size_type argPos = url.find('?'); bool hasArgs = (argPos != string::npos); if (hasArgs) { argStr = url.substr(argPos + 1); url.erase(argPos); } // parse the string before the '?' splitString(url, '/', strList, true); if (strList.getCount() >= 2) { category = strList[0]; command = strList[1]; result = true; } // parse the args if (result) { argList.clear(); splitString(argStr, '&', strList, true); for (int i = 0; i < strList.getCount(); ++i) { StrList parts; splitString(strList[i], '=', parts, true); if (parts.getCount() == 2 && !parts[0].empty()) { argList.add(parts[0], parts[1]); } } } return result; }
TEST(rolestatus, builder) { RoleStatusBuilder msg; msg.setRole(OFPCR_ROLE_MASTER); msg.setReason(kFakeReason); msg.setGenerationId(0x2222222222222222); PropertyList props; props.add(RoleStatusPropertyExperimenter{0x12345678, 0xABACABAC, {"foo", 3}}); msg.setProperties(props); MemoryChannel channel{OFP_VERSION_5}; (void)msg.send(&channel); EXPECT_EQ(40, channel.size()); EXPECT_HEX( "051E00280000000100000002110000002222222222222222FFFF000F12345678ABACABAC" "666F6F00", channel.data(), channel.size()); Message message{channel.data(), channel.size()}; message.normalize(); const RoleStatus *m = RoleStatus::cast(&message); EXPECT_TRUE(m); EXPECT_EQ(OFPCR_ROLE_MASTER, m->role()); EXPECT_EQ(kFakeReason, m->reason()); EXPECT_EQ(0x2222222222222222, m->generationId()); EXPECT_EQ(1, m->properties().itemCount()); for (auto &iter : m->properties()) { EXPECT_EQ(RoleStatusPropertyExperimenter::type(), iter.type()); auto &expProp = iter.property<RoleStatusPropertyExperimenter>(); EXPECT_EQ(0x12345678, expProp.experimenter()); EXPECT_EQ(0xABACABAC, expProp.expType()); EXPECT_EQ(ByteRange("foo", 3), expProp.expData()); } }