Beispiel #1
0
 public static Address Parse(String str)
 {
     char[] delimiter = { '.' };
     String[] _strArray = str.Split(delimiter);
     int _net = int.Parse(_strArray[0]);
     int _sub = int.Parse(_strArray[1]);
     int _host = int.Parse(_strArray[2]);
     Address addr = new Address(_net, _sub, _host);
     return addr;
 }
Beispiel #2
0
 //konwersja adresu na przypisany mu port w routelist
 public int AddressToPort(Address sprawdzany)
 {
     int port = 0;
     for (int i = 0; i < parent.routeList.Count; i++)
     {
         if (parent.routeList.ElementAt(i).destAddr.Equals(sprawdzany))//jak adres się zgadza to mamy szukany port do wysyłki
         {
             port = parent.routeList.ElementAt(i).port;
             break;
         }
     }
     return port;
 }
Beispiel #3
0
 /// <summary>
 /// Próbuje parsować string na obiekt Address. Użycie tej funkcji jest analogiczne to wszystkich innych TryParsów 
 /// </summary>
 /// <param name="str">input string</param>
 /// <param name="addr">output Address object</param>
 /// <returns>czy sie udało?</returns>
 public static bool TryParse(String str, out Address addr)
 {
     char[] delimiter = { '.' };
     String[] _strArray = str.Split(delimiter);
     if (_strArray.Length == 3) {
         try {
             int _net = int.Parse(_strArray[0]);
             int _sub = int.Parse(_strArray[1]);
             int _host = int.Parse(_strArray[2]);
             addr = new Address(_net, _sub, _host);
             return true;
         } catch {
             addr = null;
             return false;
         }
     } else {
         addr = null;
         return false;
     }
 }
Beispiel #4
0
        public void AddSingleEntry(Address address, int port, int vpi, int vci, int callID)
        {
            List<PortVPIVCI> _pvvList = new List<PortVPIVCI>();
            if (NEWVCARRAY.ContainsKey(lastCalledUser)) {
                NEWVCARRAY.TryGetValue(lastCalledUser, out _pvvList);
            }
            try {
                NEWVCARRAY.Remove(lastCalledUser);
            } catch { }
            _pvvList.Add(new PortVPIVCI(port, vpi, vci));
            NEWVCARRAY.Add(lastCalledUser, _pvvList);

            List<int> _connidList = new List<int>();
            if (NEWCONNIDARRAY.ContainsKey(lastCalledUser))
            {
                NEWCONNIDARRAY.TryGetValue(lastCalledUser, out _connidList);
            }
            try
            {
                NEWCONNIDARRAY.Remove(lastCalledUser);
            }
            catch { }
            _connidList.Add(callID);
            NEWCONNIDARRAY.Add(lastCalledUser, _connidList);

            AddrPortVPIVCIArray.Add(new PortVPIVCI(port, vpi, vci), address);
            SetText("Dodaję wpis w tablicy VCArray na port " + port + " VPI " + vpi + " VCI " + vci + "\n");
            if (lastCalledAddress != null) {
                if (addrCallIDDict.ContainsKey(lastCalledAddress)) {
                    addrCallIDDict.Remove(lastCalledAddress);
                    addrCallIDDict.Add(lastCalledAddress, callID);
                } else addrCallIDDict.Add(lastCalledAddress, callID);
            }
            String _str;
            if (lastCalledUser != null) _str = "[ " + port + " , " + vpi + " , " + vci + " ] : " + lastCalledUser;
            else _str = "[ " + port + " , " + vpi + " , " + vci + " ]";
            howToSendDict.Add(_str, new PortVPIVCI(port, vpi, vci));
            BindingSource bs = new BindingSource();
            bs.DataSource = howToSendDict.Keys;
            this.Invoke((MethodInvoker)delegate() {
                howToSendComboBox.DataSource = bs;
                sendText.Enabled = true;
            });
        }
Beispiel #5
0
        public bool ZwolnijZasob(Address a1, Address a2)
        {
            int result=0;
            for (int i = 0; i < parent.routeList.Count; i++)
            {
                if (parent.routeList.ElementAt(i).Equals(a1) || parent.routeList.ElementAt(i).Equals(a2))//przeszukuje całą listę w poszukiwaniu zadanych adresów
                {
                    parent.routeList.ElementAt(i).bandwidth += 2;//zwalnianie zasobów
                    result++;
                }

            }
            if (result == 2)//gdy oba uda się zwolnić to sukces
                return true;
            else
                return false;
        }
Beispiel #6
0
        public bool ZajmijZasob(Address a1, Address a2)
        {
            int result = 0;
            for (int i = 0; i < parent.routeList.Count; i++)
            {
                if (parent.routeList.ElementAt(i).Equals(a1) || parent.routeList.ElementAt(i).Equals(a2))//przeszukuję całą listę
                {
                    if (parent.routeList.ElementAt(i).bandwidth<2)
                    {
                        break;
                    }
                    parent.routeList.ElementAt(i).bandwidth -= 2;//zajmuje zasób
                    result++;
                }

            }
            if (result == 2)//gdy oba uda się zająć to sukces
                return true;
            else
                return false;
        }
Beispiel #7
0
 /// <summary>
 /// metoa ustalająca adres RC
 /// </summary>
 /// <returns>czy się udało czy nie</returns>
 public bool setAddress()
 {
     int _netNum;
     int _subnetNum;
     if (int.TryParse(networkNumberTextBox.Text, out _netNum))
         if (int.TryParse(subnetTextBox.Text, out _subnetNum)) {
             myAddr = new Address(_netNum, _subnetNum, 0);
             Routix.ActiveForm.Text = "Routix " + myAddr.ToString();
             return true;
         } else {
             Routix.ActiveForm.Text = "Routix";
             return false;
         } else {
         Routix.ActiveForm.Text = "Routix";
         return false;
     }
 }
Beispiel #8
0
        /// <summary>
        /// wątek odbierający wiadomości z chmury
        /// </summary>
        public void receiver()
        {
            while (isConnectedToCloud) {
                BinaryFormatter bf = new BinaryFormatter();
                try {
                    SPacket receivedPacket = (Packet.SPacket)bf.Deserialize(networkStream);
                    //_msg = reader.ReadLine();
                    if (isDebug) SetText("Odczytano:\n" + receivedPacket.ToString());
                    List<String> _msgList = receivedPacket.getParames();
                    Address _senderAddr;
                    if (Address.TryParse(receivedPacket.getSrc(), out _senderAddr)) {
                        if (_senderAddr.host == 0) {
                            #region FROM ANOTHER RC
                            if (_msgList[0] == "TOPOLOGY") {
                                try {
                                    _msgList.RemoveAt(0);
                                    String[] _RCmsg = _msgList.ToArray();
                                    int realSenderSubnet = int.Parse(_RCmsg[_RCmsg.Length - 1]);
                                    int srcSubnetNumber = int.Parse(_RCmsg[_RCmsg.Length - 1]); //ostatnia część wiadomości to numer podsieci-źródła wiadomości
                                    int[] subn = new int[_RCmsg.Length - 2];
                                    for (int i = 0; i < _RCmsg.Length - 2; i++) { //tutaj -2 by ominąć elementy "VIA" i numer podsieci-źródła wiadomości
                                        subn[i] = int.Parse(_RCmsg[i]);
                                    }
                                    foreach (int subnet in subn) {
                                        string _originSubnetAddr = _senderAddr.network + "." + realSenderSubnet + ".*";
                                        string _subnetAddr = myAddr.network + "." + subnet + ".*";
                                        if (subnet == myAddr.subnet) {
                                            //gdy przyszlo od podsieci bezposrednio z nami polaczonej
                                            foreach (Address myHost in availableSubnetworks.Keys) {
                                                List<string> temp;
                                                availableSubnetworks.TryGetValue(myHost, out temp);
                                                foreach (string addr in temp) {
                                                    if (addr == _senderAddr.network + "." + _senderAddr.subnet + ".*") {
                                                        if (!networkGraph.ContainsEdge(_originSubnetAddr, myHost.ToString())) {
                                                            networkGraph.AddEdge(new Edge<string>(_originSubnetAddr, myHost.ToString()));
                                                        }
                                                    }
                                                }
                                            }
                                        } else {
                                            if (!networkGraph.ContainsVertex(_subnetAddr)) {
                                                //gdy mamy już taki wezel grafu - nie rób nic
                                                networkGraph.AddVertex(_subnetAddr);
                                                SetText("Dodaję nowo odkrytą sieć " + _subnetAddr);
                                            }
                                            if (!networkGraph.ContainsEdge(_originSubnetAddr, _subnetAddr)) {
                                                //gdy jest już taka krawędź - nic nie rób
                                                networkGraph.AddEdge(new Edge<string>(_originSubnetAddr, _subnetAddr));
                                                SetText("Dodaję ścieżkę z " + _originSubnetAddr + " do " + _subnetAddr);
                                            }
                                        }

                                        if (!blockSending) sendTopology();

                                        foreach (int _subne in availableSubnetworksViaMe) {
                                            List<string> paramList = receivedPacket.getParames();
                                            if (paramList[0] != "TOPOLOGY") {
                                                paramList.Insert(0, "TOPOLOGY");
                                            }
                                            Address destAddr = new Address(myAddr.network , _subne , 0);
                                            SPacket pck = new SPacket(myAddr.ToString(), destAddr.ToString(), paramList);
                                            if (!blockSending) whatToSendQueue.Enqueue(pck);
                                        }
                                        fillGraph();
                                        ChangeButton(false);
                                    }
                                } catch (Exception e) {
                                    //SetText("Wyjątek przy ustalaniu topologii sieci, do poprawy :<\n" + e.Message);
                                }
                            }
                            #endregion
                        } else if (_senderAddr.host == 1) {
                            #region FROM CC
                            //_msgList.RemoveAt(0);
                            String[] _CCmsg = _msgList.ToArray();
                            if (_CCmsg[0] == "REQ_ROUTE") {
                                IVertexAndEdgeListGraph<string, Edge<string>> graph = networkGraph;
                                string root = _CCmsg[1];
                                string target = _CCmsg[2];
                                if (_CCmsg.Length == 4)
                                {

                                    AdjacencyGraph<String, Edge<String>> _graph = copyGraph(networkGraph);
                                    _graph.RemoveVertex(_CCmsg[3]);
                                    graph = _graph;
                                }
                                numberOfRoutes++;
                                sendRoute[numberOfRoutes] = true;
                                calculatePath(graph, root, target, numberOfRoutes);
                            }
                            #endregion
                        } else {
                            #region FROM LRM
                            //_msgList.RemoveAt(0);
                            String[] _LRMmsg = _msgList.ToArray();
                            //gdy logowanie się LRM
                            if (_LRMmsg[0] == "HELLO") {
                                Address _addr;
                                if (Address.TryParse(_LRMmsg[1], out _addr)) {
                                    if (networkGraph.ContainsVertex(_addr.ToString())) {
                                        List<String> _params = new List<String>();
                                        _params.Add("ADDR_TAKEN");
                                        SPacket packet = new SPacket(myAddr.ToString(), _senderAddr.ToString(), _params);
                                        whatToSendQueue.Enqueue(packet);
                                    } else {
                                        networkGraph.AddVertex(_addr.ToString());
                                        if (isDebug) SetText("Dodano węzeł grafu");
                                        fillGraph();
                                        //List<String> _params = new List<String>();
                                        //_params.Add("REQ_TOPOLOGY");
                                        //SPacket packet = new SPacket(myAddr.ToString(), _senderAddr.ToString(), _params);
                                        //whatToSendQueue.Enqueue(packet);
                                    }
                                }
                            }
                            if (_LRMmsg[0] == "DEAD") {
                                Address deadAddr;
                                if (Address.TryParse(_LRMmsg[1], out deadAddr)) {
                                    if (networkGraph.ContainsVertex(deadAddr.ToString())) {
                                        networkGraph.RemoveVertex(deadAddr.ToString());
                                        fillGraph();
                                        SetText("Węzeł o adresie " + deadAddr.ToString() + " przestał działać, usuwam go z grafu");
                                    }
                                }
                            }
                            if (_LRMmsg[0] == "TOPOLOGY") {
                                String[] _neighbors = new String[_LRMmsg.Length - 1];
                                for (int i = 1; i < _LRMmsg.Length; i++) {
                                    _neighbors[i - 1] = _LRMmsg[i];
                                }
                                foreach (String str in _neighbors) {
                                    Address _destAddr;
                                    Edge<string> x; //tylko temporary
                                    if (Address.TryParse(str, out _destAddr)) {
                                        string destAddr;
                                        //gdy przyszło info o wezle z innej podsieci
                                        if (_destAddr.subnet != myAddr.subnet) {
                                            subnetConnections.Add(new KeyValuePair<Address,Address>(_senderAddr, _destAddr));
                                            //dodaje informację o tym że ta sieć jest osiągalna przeze mnie
                                            if (!availableSubnetworksViaMe.Contains(_destAddr.subnet)) {
                                                availableSubnetworksViaMe.Add(_destAddr.subnet);
                                            }
                                            destAddr = _destAddr.network + "." + _destAddr.subnet + ".*";
                                            List<String> temp = new List<string>();
                                            if (availableSubnetworks.ContainsKey(_senderAddr)) {
                                                if (availableSubnetworks.TryGetValue(_senderAddr, out temp)) {
                                                    availableSubnetworks.Remove(_senderAddr);
                                                }
                                            }
                                            temp.Add(destAddr);
                                            availableSubnetworks.Add(_senderAddr, temp);
                                        } else destAddr = _destAddr.ToString();

                                        //jeśli jest już taka ścieżka nic nie rób
                                        if (networkGraph.TryGetEdge(_senderAddr.ToString(), destAddr, out x)) {
                                        }
                                            //jeśli nie ma
                                        else {
                                            //jeśli nie ma w węzłach grafu węzła z topologii - dodaj go
                                            if (!networkGraph.Vertices.Contains(destAddr)) networkGraph.AddVertex(destAddr);
                                            //dodaj ścieżkę
                                            networkGraph.AddEdge(new Edge<String>(_senderAddr.ToString(), destAddr));
                                            if (isDebug) SetText("Dodano ścieżkę z " + _senderAddr.ToString() + " do " + destAddr);
                                            //rysuj graf
                                            fillGraph();
                                        }
                                    }
                                }
                            }
                            //gdy przyszła wiadomość że łącze jest wolne
                            if (_LRMmsg[0] == "YES") {
                                lock (_nodesInPath) {
                                    int _index = int.Parse(_LRMmsg[2]);
                                    if (_nodesInPath[_index].Contains(_LRMmsg[1])) _nodesInPath[_index].Remove(_LRMmsg[1]);
                                    string[] _msgArr = _LRMmsg[1].Split('.');
                                    string temp = _msgArr[0] + "." + _msgArr[1] + ".*";
                                    if (_nodesInPath[_index].Contains(temp)) _nodesInPath[_index].Remove(temp);
                                    if (_nodesInPath[_index].Count == 0) {
                                        List<string> _routeMsg = new List<string>();
                                        string ccAddr = myAddr.network + "." + myAddr.subnet + ".1";
                                        _routeMsg.Add("ROUTE");
                                        foreach (string str in nodesInPath[_index]) _routeMsg.Add(str);
                                        SPacket packet = new SPacket(myAddr.ToString(), ccAddr, _routeMsg);
                                        if (sendRoute[_index])
                                        {
                                            whatToSendQueue.Enqueue(packet);
                                            sendRoute[_index] = false;
                                        }
                                    }
                                }
                            }
                            //gdy brak zasobów
                            if (_LRMmsg[0] == "NO") {
                                lock (_nodesInPath) {
                                    int _index = int.Parse(_LRMmsg[2]);
                                    string _root = nodesInPath[_index][0];
                                    string _target = nodesInPath[_index][nodesInPath.Count-1];
                                    numberOfRoutes++;
                                    if (_nodesInPath.Count != numberOfRoutes + 1) {
                                        while (_nodesInPath.Count != numberOfRoutes + 1) {
                                            _nodesInPath.Add(new List<string>());
                                        }
                                    }
                                    if (nodesInPath.Count != numberOfRoutes + 1) {
                                        while (nodesInPath.Count != numberOfRoutes + 1) {
                                            nodesInPath.Add(new List<string>());
                                        }
                                    }
                                    _nodesInPath[numberOfRoutes] = new List<string>();
                                    nodesInPath[numberOfRoutes] = new List<string>();
                                    //tymczasowy graf reprezentujący sieć bez zajętego łącza
                                    AdjacencyGraph<String, Edge<String>> _networkGraph = copyGraph(networkGraph);
                                    Edge<string> edge;
                                    _networkGraph.TryGetEdge(receivedPacket.getSrc(), _LRMmsg[1], out edge);
                                    _networkGraph.RemoveEdge(edge);
                                    //_networkGraph.RemoveEdge(new Edge<String>(receivedPacket.getSrc(), _LRMmsg[1]));
                                    //_networkGraph.RemoveEdge(new Edge<String>(_LRMmsg[1], receivedPacket.getSrc()));
                                    IVertexAndEdgeListGraph<string, Edge<string>> graph = _networkGraph;
                                    fillGraph();
                                    calculatePath(graph, _root, _target, numberOfRoutes);
                                }
                            }
                            #endregion
                        }
                    }
                } catch {
                    SetText("WUT");
                    if (++exceptionCount == 5) {
                        this.Invoke((MethodInvoker)delegate() {
                            isConnectedToCloud = false;
                            this.sendTopologyButton.Enabled = blockSending ? true : false;
                            conToCloudButton.Text = "Połącz";
                            SetText("Rozłączono!");
                            if (cloudSocket != null) cloudSocket.Close();
                        });
                    }
                }
            }
        }
 public userData(string userName, Address userAddr, int userCap, bool canReq)
 {
     this.userName = userName;
     this.userAddr = userAddr;
     this.userCap = userCap;
     this.canReq = canReq;
 }
Beispiel #10
0
 public void RemoveSingleEntry(Address address, int port, int vpi, int vci, int callID)
 {
     AddrPortVPIVCIArray.Remove(new PortVPIVCI(port, vpi, vci));
     SetText("Usuwam wpis w tablicy VCArray: port " + port + " VPI " + vpi + " VCI " + vci + "\n");
     String _str = "[ " + port + " , " + vpi + " , " + vci + " ]";
     string _strToDelete = String.Empty;
     foreach (string _shown in howToSendDict.Keys)
     {
         if (_shown.Contains(_str))
         {
             _strToDelete = _shown;
         }
     }
     try
     {
         howToSendDict.Remove(_strToDelete);
         BindingSource bs = new BindingSource();
         bs.DataSource = howToSendDict.Keys;
         this.Invoke((MethodInvoker)delegate()
         {
             howToSendComboBox.DataSource = bs;
         });
     }
     catch
     {
         SetText("Nie usunąłem wpisu z comboBoxa :<\n");
     }
 }
Beispiel #11
0
        public void readConfig(String path, bool justToOverload)
        {
            try {
                //myAddress = Address.Parse(nAddr);
                //isNodeAddressSet = true;
                //NodeNetworkNumberField.Text = String.Empty + myAddress.network;
                //NodeSubnetworkNumberField.Text = String.Empty + myAddress.subnet;
                //NodeHostNumberField.Text = String.Empty + myAddress.host;
                SetText("Wczytuje plik konfiguracyjny z " + path + "\n");
                //String path = "config" + nAddr + ".txt";
                using (StreamReader sr = new StreamReader(path)) {
                    string[] lines = System.IO.File.ReadAllLines(path);
                    foreach (String line in lines) {
                        String[] command = line.Split(' ');
                        if (command[0] == "ADD_CONNECTION") {
                            try {
                                if (VCArray.ContainsKey(command[1])) {
                                    List<PortVPIVCI> temp;
                                    VCArray.TryGetValue(command[1], out temp);
                                    temp.Add(new PortVPIVCI(int.Parse(command[2]), int.Parse(command[3]), int.Parse(command[4])));
                                    VCArray.Remove(command[1]);
                                    VCArray.Add(command[1], temp);
                                    SetText("Dodaję połączenie z klientem " + command[1] + " na porcie "
                                    + command[2] + " VPI " + command[3] + " VCI " + command[4] + "\n");
                                } else {
                                    List<PortVPIVCI> temp = new List<PortVPIVCI>();
                                    temp.Add(new PortVPIVCI(int.Parse(command[2]), int.Parse(command[3]), int.Parse(command[4])));
                                    VCArray.Add(command[1], temp);
                                    SetText("Dodaję połączenie z klientem " + command[1] + " na porcie "
                                    + command[2] + " VPI " + command[3] + " VCI " + command[4] + "\n");
                                }

                                if (!otherClients.Contains(command[1])) {
                                    otherClients.Add(command[1]);
                                    SetText("Dodaję klienta " + command[1] + "\n");
                                }
                            } catch (IndexOutOfRangeException) {
                                SetText("Komenda została niepoprawnie sformułowana (za mało parametrów)\n");
                            }
                        } else if (command[0] == "ADD_CLIENT") {
                            try {
                                otherClients.Add(command[1]);
                                SetText("Dodaję klienta " + command[1] + "\n");
                            } catch (IndexOutOfRangeException) {
                                SetText("Komenda została niepoprawnie sformułowana (za mało parametrów)\n");
                            }
                        } else if (command[0] == "ADD_ROUTE") {
                            Address adr;
                            int port;
                            int band;
                            if (int.TryParse(command[1], out port)) {
                                if (Address.TryParse(command[2], out adr)) {
                                    if (int.TryParse(command[3], out band)) {
                                        List<int> _VPIList = new List<int>();
                                        for (int i = 4; i < command.Length; i++) {
                                            int vpi;
                                            if (int.TryParse(command[i], out vpi)) {
                                                _VPIList.Add(vpi);
                                            }
                                        }
                                        routeList.Add(new Route(adr, band, port, _VPIList));
                                    } else SetText("Zły format danych\n");
                                } else SetText("Zły format danych\n");
                            } else SetText("Zły format danych\n");
                        } else if (command[0] == "SET_ADDR") {
                            try {
                                myAddress = new Address(int.Parse(command[1]), int.Parse(command[2]), int.Parse(command[3]));
                                isClientNumberSet = true;
                                ClientNetworkNumberField.Text = String.Empty + myAddress.network;
                                ClientSubnetworkNumberField.Text = String.Empty + myAddress.subnet;
                                ClientHostNumberField.Text = String.Empty + myAddress.host;
                                SetText("Ustalam adres klienta jako " + myAddress.ToString() + "\n");
                            } catch {
                                SetText("komenda ustalenia adresu została niepoprawnie sformułowana");
                            }
                        }
                    }
                }
            } catch (Exception exc) {
                SetText("Błąd podczas konfigurowania pliku konfiguracyjnego\n");
                SetText(exc.Message + "\n");
            }
        }
Beispiel #12
0
 private void setClientNumber_Click(object sender, EventArgs e)
 {
     try {
         int clientAddressNetwork = int.Parse(ClientNetworkNumberField.Text);
         int clientAddressSubnet = int.Parse(ClientSubnetworkNumberField.Text);
         int clientAddressHost = int.Parse(ClientHostNumberField.Text);
         isClientNumberSet = true;
         myAddress = new Address(clientAddressNetwork, clientAddressSubnet, clientAddressHost);
         SetText("Adres klienta ustawiony jako " + myAddress.ToString() + "\n");
         Clientix.ActiveForm.Text = "Clientix " + myAddress.ToString();
     } catch {
         isClientNumberSet = false;
         SetText("Błędne dane wejściowe\n");
         Clientix.ActiveForm.Text = "Clientix";
     }
 }
Beispiel #13
0
 public Route(Address addr, int band, int port, List<int> VPIList)
 {
     destAddr = addr;
     bandwidth = band;
     this.port = port;
     this.VPIList = VPIList;
 }
 public bool setAddress()
 {
     int _netNum;
     int _subnetNum;
     int _hostNum;
     if (int.TryParse(networkNumberTextBox.Text, out _netNum)){
         if (int.TryParse(subnetTextBox.Text, out _subnetNum)) {
             if (int.TryParse(hostNumberTextBox.Text, out _hostNum)) {
                 myAddr = new Address(_netNum, _subnetNum, _hostNum);
                 return true;
             } else return false;
         } else return false;
     }else return false;
 }
 private void sendButton_Click(object sender, EventArgs e)
 {
     try {
         Address source = new Address(int.Parse(srcNet.Text), int.Parse(srcSubnet.Text), int.Parse(srcHost.Text));
         Address destination = new Address(int.Parse(destNet.Text), int.Parse(destSubnet.Text), int.Parse(destHost.Text));
         SPacket packet = new SPacket(source.ToString(), destination.ToString(), msg.Text);
         whatToSendQueue.Enqueue(packet);
     } catch {
         SetText("Nie wysłało");
     }
 }
 public UserData(string userName, Address userAddr, int userCap, bool canReq)
 {
     this.userName = userName;
     this.userAddr = userAddr;
     this.userCap = userCap;
     this.canReq = canReq;
     this.userMappings = new List<NodeMapping>();
     this.possibleOutVPs = new List<VirtualPath>();
 }
Beispiel #17
0
 private void setNodeNumber_Click(object sender, EventArgs e)
 {
     try {
         int nodeAddressNetwork = int.Parse(NodeNetworkNumberField.Text);
         int nodeAddressSubnet = int.Parse(NodeSubnetworkNumberField.Text);
         int nodeAddressHost = int.Parse(NodeHostNumberField.Text);
         isNodeAddressSet = true;
         myAddress = new Address(nodeAddressNetwork, nodeAddressSubnet, nodeAddressHost);
         SetText("Numer węzła ustawiony jako " + myAddress.ToString() + "\n");
         Nodix.ActiveForm.Text = "Nodix " + myAddress.ToString();
     } catch {
         isNodeAddressSet = false;
         SetText("Błędne dane wejściowe\n");
         Nodix.ActiveForm.Text = "Nodix";
     }
 }
Beispiel #18
0
 public void readConfig(String path, bool justToOverload)
 {
     try {
         //myAddress = Address.Parse(nAddr);
         //isNodeAddressSet = true;
         //NodeNetworkNumberField.Text = String.Empty + myAddress.network;
         //NodeSubnetworkNumberField.Text = String.Empty + myAddress.subnet;
         //NodeHostNumberField.Text = String.Empty + myAddress.host;
         SetText("Wczytuje plik konfiguracyjny z " + path + "\n");
         //String path = "config" + nAddr + ".txt";
         using (StreamReader sr = new StreamReader(path)) {
             string[] lines = System.IO.File.ReadAllLines(path);
             foreach (String line in lines) {
                 String[] command = line.Split(' ');
                 if (command[0] == "ADD") {
                     try {
                         addSingleEntry(int.Parse(command[1]), int.Parse(command[2]), int.Parse(command[3]),
                             int.Parse(command[4]), int.Parse(command[5]), int.Parse(command[6]));
                     } catch (IndexOutOfRangeException) {
                         SetText("Komenda została niepoprawnie sformułowana (za mało parametrów)\n");
                     }
                 } else if (command[0] == "CLEAR") {
                     clearTable();
                 } else if (command[0] == "ADD_ROUTE") {
                     Address adr;
                     int port;
                     int band;
                     if (int.TryParse(command[1], out port)) {
                         if (Address.TryParse(command[2], out adr)) {
                             if (int.TryParse(command[3], out band)) {
                                 List<int> _VPIList = new List<int>();
                                 for (int i = 4; i < command.Length; i++) {
                                     int vpi;
                                     if (int.TryParse(command[i], out vpi)) {
                                         _VPIList.Add(vpi);
                                     }
                                 }
                                 routeList.Add(new Route(adr, band, port, _VPIList));
                                 SetText("Dodaję ścieżkę do " + adr.ToString() + " o przepustowości " + band + " Mbit/s na porcie " + port + "\n");
                                 String _VPIListString = String.Empty;
                                 foreach (int i in _VPIList) {
                                     _VPIListString += i + " ";
                                 }
                                 SetText("VPaths na tym łączu to " + _VPIListString + "\n");
                             } else SetText("Zły format danych\n");
                         } else SetText("Zły format danych\n");
                     } else SetText("Zły format danych\n");
                 } else if (command[0] == "SET_ADDR") {
                     try{
                         myAddress = new Address(int.Parse(command[1]), int.Parse(command[2]), int.Parse(command[3]));
                         isNodeAddressSet = true;
                         NodeNetworkNumberField.Text = String.Empty + myAddress.network;
                         NodeSubnetworkNumberField.Text = String.Empty + myAddress.subnet;
                         NodeHostNumberField.Text = String.Empty + myAddress.host;
                         SetText("Ustalam adres węzła jako " + myAddress.ToString() + "\n");
                     } catch {
                         SetText("komenda ustalenia adresu została niepoprawnie sformułowana");
                     }
                 }
             }
         }
     } catch (Exception exc) {
         SetText("Błąd podczas konfigurowania pliku konfiguracyjnego\n");
         SetText(exc.Message + "\n");
     }
 }