-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
144 lines (91 loc) · 4.63 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from Packets import BeaconPacket
from Packets import ReportPacket
from Packets import Packets
import init_config
import socket
import ifaddr
import subprocess
import os
import time
import UDP_Socket
import AudioFile
import threading
import node_variables
from configparser import ConfigParser
from queue import Queue
config = ConfigParser()
config.read('config.ini')
neighbours=Queue()
############ 0. Asseganre gli Indirizzi Ip Nuovi ############
print("\n\n\t\tSTART SDNWISE\n\n")
#init_config.SetDeviceOnStart()
#print("\n\tIndirizzi Ip Asseganti\n")
############ 1. Calcolo Indirizzi Ip Nuovi ############
nodeIP = init_config.GetIp(config['GENERAL']['StationInterface'] )
#node_variables.IpClient = init_config.GetIp( config['GENERAL']['ClientInterface'] )
#print(f'Client: {node_variables.IpClient} \t Station: {node_variables.IpStation}')
#node_variables.IpDefaultGateway = init_config.GetDefaultGateway( config['GENERAL']['ClientInterface'] )
#print(f"Default Gateway: {node_variables.IpDefaultGateway}")
############ 2. Run Threads ############
#if (str(nodeIP)==str(config['GENERAL']['IpSink'])):
#node_variables.IpClient = node_variables.IpStation
ThreadUdpReceiver = UDP_Socket.ThreadReceiverUdpPackets(1, "Thread-UdpReceiver", int(config['GENERAL']['Port']) )
ThreadUdpReceiverFromController = UDP_Socket.ThreadReceiverUdpPacketsFromController(6, "Thread-UdpReceiverFromController",config['GENERAL']['IpSinkOnWan'], int(config['GENERAL']['PortFromController']) )
pckBeacon = BeaconPacket (config['GENERAL']['NetId'], config['GENERAL']['IpSink'] , nodeIP, config['GENERAL']['TTL'], config['GENERAL']['IpSink'], "" )
ThreadUdpBeacon = UDP_Socket.ThreadBeacon( 2, "Thread-Beacon", pckBeacon.getBytesFromPackets() , config['GENERAL']['IpSink'],int(config['GENERAL']['Port']) )
pckBeaconS = BeaconPacket (config['GENERAL']['NetId'], config['GENERAL']['IpController'] , nodeIP, config['GENERAL']['TTL'], config['GENERAL']['IpController'], "" )
ThreadUdpBeaconS = UDP_Socket.ThreadBeacon( 7, "Thread-Beacon", pckBeacon.getBytesFromPackets() , config['GENERAL']['IpController'],int(config['GENERAL']['PortController']) )
#if (config.get(socket.gethostname(),'Sink') == "NO"):
ThreadUdpReport = UDP_Socket.ThreadReport(3, "Thread-Report", int(config['GENERAL']['Port']), nodeIP, config['GENERAL']['IpSink'], neighbours )
ThreadRefreshARP= UDP_Socket.ThreadRefreshARP(4,"Thread-RefreshARP",neighbours)
#else:
# ThreadUdpReport = UDP_Socket.ThreadReport(3, "Thread-Report", int(config['GENERAL']['Port']), node_variables.IpStation, node_variables.IpDefaultGateway )
#ThreadPrintInfo = UDP_Socket.ThreadPrintInfoNode(4,"Thread-Info")
#ThreadAudioFile = AudioFile.ThreadSendDataAudio(5,"Tread-Audio")
ThreadRefreshARP.start()
if (str(nodeIP)!=str(config['GENERAL']['IpSink'])):
print("Processo avviato. Non sono il sink: ", str(nodeIP))
ThreadUdpBeacon.start() #da indentare correttamente
ThreadUdpReport.start()
ThreadUdpReceiver.start()
# ThreadAudioFile.start()
if (str(nodeIP)==str(config['GENERAL']['IpSink'])):
print("Processo avviato. Sono il sink: ", str(nodeIP))
ThreadUdpReceiver.start()
ThreadUdpBeaconS.start()
ThreadUdpReceiverFromController.start()
#
#ThreadPrintInfo.start()
############ 2. Avvio Server UDP ############
# UDP_Socket.RunReceiverProcess(IpStation,4000)
# UDP_Socket.ReceiverPacket(IpStation)
# while True:
# UDP_Socket.SendPacket("Ciao","192.168.0.130")
# MULTICAST
# if ( socket.gethostname() == "Omega-1D63"):
# server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
# server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
# server.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
# server.settimeout(0.2)
# message = b"your very important message"
# while True:
# server.sendto(message, ('<broadcast>', 37020))
# print("message sent!")
# time.sleep(1)
# if ( socket.gethostname() == "Omega-1D06"):
# client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) # UDP
# client.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
# client.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
# client.bind(("", 37020))
# while True:
# data, addr = client.recvfrom(1024)
# print("received message: %s"%data)
# PACKETS
# p1 = BeaconPacket("1","10.10.0.1","10.10.0.0","100","10.10.0.1")
# print(p1.printFullPacket())
# print(p1.printLitePacket())
# p1.getBytesFromPackets()
# test = bytearray(b'-1--46------10.10.0.1------10.10.0.0-0100------10.10.0.1Payload BEACON')
# p2 = Packets.getPacketFromBytes(test)
# print(p2.printFullPacket())
# print(p2.printLitePacket())