public void Start(string configPath) { AddLog("Starting a node...", LogType.Information); try { Config = NetworkNodeConfig.ParseConfig(configPath); } catch (Exception e) { AddLog($"Exception: {e.Message}", LogType.Error); return; } networkNodeRoutingTables.LoadTablesFromConfig(Config, Window); networkNodeRoutingTables.StartManagementAgent(); ConnectToCloud(); while (true) { while (ConnectedSocket == null || !ConnectedSocket.Connected) { AddLog("Retrying connection to cable cloud...", LogType.Information); ConnectToCloud(); } try { var package = ConnectedSocket.Receive(); AddLog($"Received package: {package} at port {package.Port}", LogType.Received); Task.Run(() => HandlePackage(package)); } catch (InvalidMPLSPackageException) { AddLog("Received package was not a valid package.", LogType.Error); } catch (SocketException e) { // ignore timeout exceptions if (e.SocketErrorCode != SocketError.TimedOut) { if (e.SocketErrorCode == SocketError.Shutdown || e.SocketErrorCode == SocketError.ConnectionReset) { AddLog("Connection to Cloud broken!", LogType.Error); continue; } else { AddLog($"{e.Source}: {e.SocketErrorCode}", LogType.Error); } } } } }
public static NetworkNodeConfig ParseConfig(string FileName) { var content = File.ReadAllLines(FileName).ToList(); var config = new NetworkNodeConfig(); config.ManagementSystemAddress = IPAddress.Parse(GetProperty(content, "MANAGEMENTADDRESS")); config.ManagementSystemPort = ushort.Parse(GetProperty(content, "MANAGEMENTPORT")); config.NodeName = GetProperty(content, "NODENAME"); config.CloudAddress = IPAddress.Parse(GetProperty(content, "CLOUDADDRESS")); config.CloudPort = ushort.Parse(GetProperty(content, "CLOUDPORT")); return(config); }
public ManagementAgent(NetworkNodeConfig networkNodeConfig, MainWindow window) { Config = networkNodeConfig; Window = window; }
public void LoadTablesFromConfig(NetworkNodeConfig Config, MainWindow window) { managementAgent = new ManagementAgent(Config, window); managementAgent.ModfifyForwardingTable += HandleModifyForwardingTable; window.Dispatcher.Invoke(() => window.Title = Config.NodeName); }