Switch.h 1.46 KB
Newer Older
/jdi/'s avatar
/jdi/ committed
1
2
3
4
5
6
7
8
9
10
11
/*
 * Switch.h
 *
 *  Created on: 29.09.2015
 *      Author: jdi
 */

#ifndef SWITCH_H_
#define SWITCH_H_

#include <string>
/jdi/'s avatar
/jdi/ committed
12
#include <map>
/jdi/'s avatar
/jdi/ committed
13
14
15
#include "../include/rapidjson/document.h"
#include "../include/rapidjson/prettywriter.h"
#include "Types.h"
/jdi/'s avatar
/jdi/ committed
16
17
18
19

#define DEFAULT_USER "admin"
#define DEFAULT_PASS "admin"

/jdi/'s avatar
/jdi/ committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
typedef rapidjson::Value jsonNode;

/*
template<typename T>
jsonNode to_json(const T &x) {
	// TODO Throw undefined
	return NULL;
}

template<> jsonNode to_json<vlan>(const vlan &x) {
	jsonNode ret;
	return ret;
}

template<typename T>
T from_json(const jsonNode &s) {
// TODO Throw not implemented
	return NULL;
}

template<> vlan from_json<vlan>(const jsonNode &s) {
	vlan ret;
	return ret;
}*/

/jdi/'s avatar
/jdi/ committed
45
46
47
48
49
50
struct vlan {
	int vlan_id;
	std::string name;
};

struct port {
/jdi/'s avatar
/jdi/ committed
51
52
	byte id;
	byte status;
/jdi/'s avatar
/jdi/ committed
53
54
55
56
57
58
59
60
61
	struct {
		std::vector<vlan*> tagged;
		std::vector<vlan*> untagged;
		int pvid;
	} vlan;
};

class Switch {
public:
/jdi/'s avatar
/jdi/ committed
62
63
	Switch() {
	}
/jdi/'s avatar
/jdi/ committed
64
65
66
67
	int parse(datasets);
	int parse(dataset);
	int parse(std::string);
	std::string toString();
/jdi/'s avatar
/jdi/ committed
68
69
70
71
	struct {
		std::string type;
		std::string hardware_version;
		std::string firmware_version;
/jdi/'s avatar
/jdi/ committed
72
		macAddr mac { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
/jdi/'s avatar
/jdi/ committed
73
74
75
76
	} device;
	struct {
		std::string password = DEFAULT_PASS;
		std::string username = DEFAULT_USER;
/jdi/'s avatar
/jdi/ committed
77
		std::string hostname;
/jdi/'s avatar
/jdi/ committed
78
		ipAddr ip_addr { 0, 0, 0, 0, };
/jdi/'s avatar
/jdi/ committed
79
80
		ipAddr ip_mask;
		ipAddr gateway;
/jdi/'s avatar
/jdi/ committed
81
		bool dhcp;
/jdi/'s avatar
/jdi/ committed
82
	} settings;
/jdi/'s avatar
/jdi/ committed
83
private:
/jdi/'s avatar
/jdi/ committed
84
	rapidjson::Document json;
/jdi/'s avatar
/jdi/ committed
85
86
87
88
89
	std::vector<vlan> vlans;
	std::vector<port> ports;
};

#endif /* SWITCH_H_ */