Switch.h 1.89 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
#include "Types.h"
/jdi/'s avatar
/jdi/ committed
14
15
#include "Types/bytes.h"
#include "Types/datasets.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
45
46
47
48
49
50
static std::map<int,std::string> rcv_lookup= {
	{	1, "type"},//string
	{	2, "hostname"},//string
	{	3, "mac"},//byte[6]
	{	4, "ip_addr"},//byte[4]
	{	5, "ip_mask"},//byte[4]
	{	6, "gateway"},//byte[4]
	{	7, "firmware_version"},//string
	{	8, "hardware_version"},//string
	{	9, "dhcp"}};//bool byte

static std::map<int,std::string> snd_lookup= {
		{10,"???"},//after login
		{2,"???"},//after login
		{512,"login_user"},//string
		{513,"new_user"},//string
		{514,"login_password"},//string
		{515,"new_passwoord"},//string
		{2200,"vlan"},
		{2305,"???"},//sent before login and before change hostname
		{4608,"port_trunk"},//byte[5] last byte bitmask??
		{8192,"mtu_vlan"},//byte[2] first byte bool,	second byte port id
		{8449,"port_vlan"},//???
		{8705,"802.1q vlan"},//???
		{8706,"802.1q vlan pvid"},//????
		{12288,"QoS Basic"},//bool = QoS Mod
		{16640,"port_mirror"},//byte[10] second byte port id??
		{17152,"loop_prevention"},//bool byte
		//{0000," "},
};

/jdi/'s avatar
/jdi/ committed
51

/jdi/'s avatar
/jdi/ committed
52
53
54
55
56
57
struct vlan {
	int vlan_id;
	std::string name;
};

struct port {
/jdi/'s avatar
/jdi/ committed
58
59
	byte id;
	byte status;
/jdi/'s avatar
/jdi/ committed
60
61
62
63
64
65
66
67
68
	struct {
		std::vector<vlan*> tagged;
		std::vector<vlan*> untagged;
		int pvid;
	} vlan;
};

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

#endif /* SWITCH_H_ */