lookup clean up

This commit is contained in:
j3d1 2016-02-25 01:47:14 +01:00
parent 69198cd6fe
commit f15abc71be
8 changed files with 79 additions and 79 deletions

View file

@ -81,7 +81,7 @@ int Program::run(vector<string> arg) {
while (optind < arg.size()) {
if (regex_match(arg[optind].c_str(), sm,
std::regex("^([a-z]+)=(.*)$"))) {
if (!snd_lookup.exists(sm[1]) && !rcv_lookup.exists(sm[1])) {
if (!lookup.exists(sm[1])) {
cerr << "Unknown argument " << arg[optind] << endl;
return 1;
}
@ -99,7 +99,7 @@ int Program::run(vector<string> arg) {
while (optind < arg.size()) {
if (regex_match(arg[optind].c_str(), sm,
std::regex("^([a-z]+)$"))) {
if (!snd_lookup.exists(sm[1]) && !rcv_lookup.exists(sm[1])) {
if (!lookup.exists(sm[1])) {
cerr << "Unknown argument " << arg[optind] << endl;
return 1;
}
@ -138,7 +138,7 @@ int printPacket(Packet p) {
cout << "Received Payload:\n\t" << p.getBody() << "\n";
} else {
for (dataset d : p.getPayload()) {
auto lookup = (options.flags.REVERSE) ? snd_lookup : rcv_lookup;
//auto lookup = (options.flags.REVERSE) ? snd_lookup : rcv_lookup;
if (lookup.exists(d.type)) {
table::set s = lookup[d.type];
if (d.len > 0) {
@ -243,9 +243,9 @@ int Program::setProperty(map<string, string> prop) {
for (auto p : prop) {
string s = p.second;
dataset d;
if (rcv_lookup.exists(p.first)) {
d.type = rcv_lookup.type(p.first);
if (rcv_lookup[p.first].format == table::STRING) {
if (lookup.exists(p.first)) {
d.type = lookup.type(p.first);
if (lookup[p.first].format == table::STRING) {
d.len = s.size() + 1;
d.value = s;
data.push_back(d);
@ -260,7 +260,7 @@ int Program::setProperty(map<string, string> prop) {
sw.parse(d);
sw.print();
datasets t = { {SND_PING, 0, {}}};
datasets t = { {PING, 0, {}}};
get(a, t, [this,data](Packet a) {
datasets d =a.getPayload();
Switch sw = Switch();
@ -288,7 +288,7 @@ int Program::getProperty(vector<string> prop) {
datasets data = { };
for (string s : prop) {
dataset d;
d.type = snd_lookup.type(s);
d.type = lookup.type(s);
data.push_back(d);
}
cout << "List:\n";
@ -342,7 +342,7 @@ int Program::reboot() {
if (devices.empty()||devices.find(b) == devices.end())
devices.insert(pair<int,Switch>(b,Switch()));
devices[a.getSwitchMac().hash()].parse(d);
datasets t = { {SND_PING, 0, {}}};
datasets t = { {PING, 0, {}}};
get(a, t, [this](Packet a) {
datasets d =a.getPayload();
cout <<devices[a.getSwitchMac().hash()].settings.hostname<<"\t";
@ -369,7 +369,7 @@ int Program::reset() {
Switch sw = Switch();
sw.parse(d);
cout <<sw.settings.hostname<<"\t";
datasets t = { {SND_PING, 0, {}}};
datasets t = { {PING, 0, {}}};
get(a, t, [this](Packet a) {
datasets d =a.getPayload();
Switch sw = Switch();

View file

@ -27,10 +27,10 @@ int Switch::print() {
int Switch::parse(dataset d) {
switch (d.type) {
case RCV_TYPE:
case TYPE:
device.type = d.value;
break;
case RCV_MAC:
case MAC:
device.mac = d.value;
break;
case FIRMWARE_VERSION:

View file

@ -1,30 +1,12 @@
enum {
#define LOOKUP_SET(id, name, num, type) RCV_ ## id = num,
#include "lookup/rcv.lst"
#include "lookup/general.lst"
#undef LOOKUP_SET
#define LOOKUP_SET(id, name, num, type) SND_ ## id = num,
#include "lookup/snd.lst"
#include "lookup/general.lst"
#undef LOOKUP_SET
#define LOOKUP_SET(id, name, num, type) id = num,
#include "lookup/rcv.lst"
#include "lookup/snd.lst"
#include "lookup/general.lst"
#define LOOKUP_SET(id, name, num, type, write) id = num,
#include "lookup/map.lst"
#undef LOOKUP_SET
};
static table rcv_lookup {
#define LOOKUP_SET(id, name, num, type) { RCV_ ## id, table::type, #name, #id },
#include "lookup/rcv.lst"
#include "lookup/general.lst"
#undef LOOKUP_SET
};
static table snd_lookup {
#define LOOKUP_SET(id, name, num, type) { SND_ ## id, table::type, #name, #id },
#include "lookup/snd.lst"
#include "lookup/general.lst"
static table lookup {
#define LOOKUP_SET(id, name, num, type, write) { id, table::type, table::write, #name, #id},
#include "lookup/map.lst"
#undef LOOKUP_SET
};

View file

@ -1,3 +1,5 @@
LOOKUP_SET(PORTS, ports, 10, DEC) //+byte, maybe number of ports
LOOKUP_SET(IGMP_SNOOPING, igmp, 4352, HEX) //???

View file

@ -1,38 +0,0 @@
LOOKUP_SET(type, TYPE, STRING) //+string
LOOKUP_SET(mac, MAC, HEX) //+byte[6]
LOOKUP_SET(firmware,FIRMWARE_VERSION, STRING)
LOOKUP_SET(hardware,HARDWARE_VERSION, STRING)
LOOKUP_SET(HOSTNAME,host, 2, STRING) //+string
LOOKUP_SET(IP_ADDR,ip, 4, DEC) //+byte[4]
LOOKUP_SET(IP_MASK,mask, 5, DEC) //+byte[4]
LOOKUP_SET(GATEWAY,gateway, 6, DEC) //+byte[4]
LOOKUP_SET(DHCP_ENABLED,dhcp, 9, BOOL) //+bool byte
LOOKUP_SET(PORT_VLAN_FOOOOO, 2101,2101, HEX)
LOOKUP_SET(PORTS, ports, 10, DEC) //+byte, maybe number of ports
LOOKUP_SET(IGMP_SNOOPING, igmp, 4352, HEX) //???
LOOKUP_SET(PORTS_SETTINGS, psetings, 4096, HEX) //+per port
LOOKUP_SET(PORT_TRUNK, trunk, 4608, HEX) //byte[5] last byte bitmask??
LOOKUP_SET(MTU_VLAN, 8192,8192, HEX) //byte[2] first byte bool,second byte port id
LOOKUP_SET(PORT_VLAN_ENABLED, 8448,8448, BOOL) //open page
LOOKUP_SET(PORT_VLAN, 8449,8449, HEX)
LOOKUP_SET(PORT_VLAN_MAX, 8450,8450, DEC)
LOOKUP_SET(VLAN_ENABLED, 8704, 8704, BOOL) //+bool byte
LOOKUP_SET(VLAN, 8705,8705, HEX) //+one set per vlan
LOOKUP_SET(VLAN_PVID, 8706,8706, HEX) //+per port
LOOKUP_SET(VLAN_FOOOO, 8707,8707, DEC) //????
LOOKUP_SET(QOS_BASIC_ENABLED, 12288,12288, BOOL) //+bool = QoS Mod
LOOKUP_SET(QOS_BASIC, 12289,12289, HEX) //+per port ???
LOOKUP_SET(BW_CONTROL_INGRESS, 12544,12544, HEX) //+per port ???
LOOKUP_SET(BW_CONTROL_EGRESS, 12545,12545, HEX) //+per port ???
LOOKUP_SET(STORM_CONTROL, 12800,12800, HEX) //+per port ???
LOOKUP_SET(PORT_MIRROR, 16640,16640, HEX) //byte[10] second byte port id???
LOOKUP_SET(PORT_STATISTICS, 16384,16384, HEX) //+per port ???
LOOKUP_SET(CABLE_TEST, 16896,16896, HEX) //+per port ???
LOOKUP_SET(LOOP_PREVENTION, 17152,17152, BOOL) //+bool byte

49
src/lookup/map.lst Normal file
View file

@ -0,0 +1,49 @@
LOOKUP_SET(TYPE, type, 1, STRING, RO) //+string
LOOKUP_SET(HOSTNAME, host, 2, STRING, RW) //+string //SYSTEM_INFO,SYSTEM_INFO, 2, HEX) //page sysinfo
LOOKUP_SET(MAC, mac, 3, HEX, RO) //+byte[6]
LOOKUP_SET(IP_ADDR, ip, 4, DEC, RW) //+byte[4]
LOOKUP_SET(IP_MASK, mask, 5, DEC, RW) //+byte[4]
LOOKUP_SET(GATEWAY, gateway, 6, DEC, RW) //+byte[4]
LOOKUP_SET(FIRMWARE_VERSION,firmware, 7, STRING, RO)
LOOKUP_SET(HARDWARE_VERSION,hardware, 8, STRING, RO)
LOOKUP_SET(DHCP_ENABLED, dhcp, 9, BOOL, RW) //+bool byte //IP_CONFIG,IP_CONFIG, 9, HEX) //page sysinfo
LOOKUP_SET(PORTS, ports, 10, DEC, RO) //+byte, maybe number of ports
LOOKUP_SET(LOGIN_USER, luser, 512, STRING, NONE) //string
LOOKUP_SET(NEW_USER, user, 513, STRING, WO) //string
LOOKUP_SET(LOGIN_PASSWORD, lpw, 514, STRING, NONE) //string
LOOKUP_SET(NEW_PASSWORD, password, 515, STRING, WO) //string
LOOKUP_SET(REBOOT, reboot, 773, BOOL, NONE) //bool byte = save config
LOOKUP_SET(RESET, reset, 1280, ACTION, NONE) //
LOOKUP_SET(FLASH, flash, 1536, ACTION, NONE) //update firmware
LOOKUP_SET(PORT_VLAN_FOOOOO,vlan21, 2101, HEX, RO)
LOOKUP_SET(VLAN_FOOOOOO, vlan22, 2200, HEX, RO) //vlan
LOOKUP_SET(SAVE, save, 2304, ACTION, NONE) //save
LOOKUP_SET(PING, ping, 2305, ACTION, NONE) //sent before SET ???
LOOKUP_SET(IGMP_SNOOPING, igmp, 4352, HEX, RW) //???
LOOKUP_SET(PORTS_SETTINGS, psetings, 4096, HEX, RW) //+per port
LOOKUP_SET(PORT_TRUNK, trunk, 4608, HEX, RW) //byte[5] last byte bitmask??
LOOKUP_SET(MTU_VLAN, 8192, 8192, HEX, UNKNOWN) //byte[2] first byte bool,second byte port id
LOOKUP_SET(PORT_VLAN_ENABLED,8448, 8448, BOOL, UNKNOWN) //open page
LOOKUP_SET(PORT_VLAN, 8449, 8449, HEX, UNKNOWN)
LOOKUP_SET(PORT_VLAN_MAX, 8450, 8450, DEC, UNKNOWN)
LOOKUP_SET(VLAN_ENABLED, 8704, 8704, BOOL, UNKNOWN) //+bool byte
LOOKUP_SET(VLAN, 8705, 8705, HEX, UNKNOWN) //+one set per vlan
LOOKUP_SET(VLAN_PVID, 8706, 8706, HEX, UNKNOWN) //+per port
LOOKUP_SET(VLAN_FOOOO, 8707, 8707, DEC, UNKNOWN) //????
LOOKUP_SET(QOS_BASIC_ENABLED,12288, 12288, BOOL, UNKNOWN) //+bool = QoS Mod
LOOKUP_SET(QOS_BASIC, 12289, 12289, HEX, UNKNOWN) //+per port ???
LOOKUP_SET(BW_CONTROL_INGRESS,12544, 12544, HEX, UNKNOWN) //+per port ???
LOOKUP_SET(BW_CONTROL_EGRESS,12545, 12545, HEX, UNKNOWN) //+per port ???
LOOKUP_SET(STORM_CONTROL, 12800, 12800, HEX, UNKNOWN) //+per port ???
LOOKUP_SET(PORT_MIRROR, 16640, 16640, HEX, UNKNOWN) //byte[10] second byte port id???
LOOKUP_SET(PORT_STATISTICS, 16384, 16384, HEX, UNKNOWN) //+per port ???
LOOKUP_SET(CABLE_TEST, 16896, 16896, HEX, UNKNOWN) //+per port ???
LOOKUP_SET(LOOP_PREVENTION, 17152, 17152, BOOL, UNKNOWN) //+bool byte

View file

@ -8,7 +8,6 @@
#include <string>
#include "table.h"
table::table(std::initializer_list<set> l) {
int i = 0;
this->data.resize(l.size());

View file

@ -13,13 +13,19 @@
class table {
public:
enum F {STRING,HEX,DEC,ACTION,BOOL,EMPTY};
struct set {
short type;
F format;
enum A {
RW, RO, WO, NONE, UNKNOWN
};
enum F {
STRING, HEX, DEC, ACTION, BOOL, EMPTY
};
struct set {
short type;
F format;
A action;
std::string name;
std::string id;
};
};
table(std::initializer_list<set> l);
const table::set operator[](std::string);
const table::set operator[](short);