Exemplo n.º 1
0
        private void SentNewRouterRecord(SlotWindow slotWindow)
        {
            try
            {
                NewLog2($"CC: Get RouteTableQueryResponse from CC", myWindow, "LightSkyBlue");

                //NewLog($"SentNewRouterRecord path.Length {path.Length}", myWindow);
                for (int i = 0; i < path.Length; i++)
                {
                    NewLog2($"Send SNP LinkConnectionRequest to LRM {path[i]}", myWindow, "LightSkyBlue");
                    int nextNode = -1;
                    if (i < (path.Length - 1))
                    {
                        nextNode = path[i + 1];
                    }
                    RouterMapRecord newRecord = new RouterMapRecord(slotWindow, nextNode);
                    string          str       = XmlSerialization.SerializeObject(newRecord);
                    string          message   = MessageNames.ADD_RECORD + " " + str;
                    string          ipaddress = nodeDict[path[i]];
                    SendMessage(ipaddress, message);
                }
            }
            catch (Exception E)
            {
                NewLog("SentNewRouterRecord : " + E.Message, myWindow);
            }
        }
 public bool AddRouterMapRecord(RouterMapRecord newRecord)
 {
     foreach (RouterMapRecord item in networknode.routerMapRecords)
     {
         if (item.slotWindow.Collide(newRecord.slotWindow))
         {
             NewLog($"Cannot add {newRecord.slotWindow.FirstSlot} {newRecord.slotWindow.NumberofSlots}", this, "LightYellow");
             return(false);
         }
     }
     NewLog($"LRM: Get SNP LinkAllocationRequest from CC; RouterMapRecord: FirstSlot: {newRecord.slotWindow.FirstSlot} NrOfSlots: {newRecord.slotWindow.NumberofSlots}", this, "LightGray");
     networknode.routerMapRecords.Add(newRecord);
     return(true);
 }
        //dodajemy record do slot table- snp
        //firstslot numberofslots destinationid iprc
        public void HandelRouterMapRecord(string[] msg)
        {
            string          resultstring = XmlSerialization.GetStringToNormal(msg);
            RouterMapRecord mapRecord    = XmlSerialization.DeserializeObject <RouterMapRecord>(resultstring);

            if (AddRouterMapRecord(mapRecord))
            {
                string message = message = MessageNames.LINK_ALLOCATION_RESPONSE
                                           + " "
                                           + XmlSerialization.SerializeObject(mapRecord.slotWindow);
                //NewLog("<potrzebne?> Dodano rekord", this);
                SendMessage(networknode.CCIPAddress, message);
                NewLog($"LRM: Send SNP LinkConnectionResponse to CC: {networknode.CCIPAddress}", this, "LightGray");
            }
            else
            {
                NewLog("Nie udało się dodać rekordu", this);
            }
            //wyslij wiadomosc do RC
            //SendMessage(iprc,message);
        }
        MyPacket RoutePacket(MyPacket packet)
        {
            try
            {
                //NewLog($"RoutePacket {packet.slotWindow.FirstSlot} {packet.slotWindow.NumberofSlots}", this);

                Predicate <RouterMapRecord> goodRecord = r => ((r.slotWindow.FirstSlot == packet.slotWindow.FirstSlot) &&
                                                               (r.slotWindow.NumberofSlots == packet.slotWindow.NumberofSlots));
                RouterMapRecord record = networknode.routerMapRecords.Find(goodRecord);
                if (null == record)
                {
                    NewLog($"RoutePacket record is null", this, "LightYellow");
                }
                if (record.DestinationID >= 0) //wysylamy do routera
                {
                    packet.Port = -record.DestinationID;
                }
                else if (networknode.HostPort >= 0) // wysylamy do hosta
                {
                    packet.Port = networknode.HostPort;
                }
                else  //wysylam do 2 domeny
                {
                    packet.Port = networknode.EdgePort;
                }
                //NewLog($"RoutePacket {packet.slotWindow.FirstSlot} {packet.slotWindow.NumberofSlots}", this);
            }
            catch (Exception ex)
            {
                NewLog($"RoutePacket {ex}", this, "LightYellow");
                foreach (var it in networknode.routerMapRecords)
                {
                    NewLog($" {it.slotWindow.FirstSlot} {it.slotWindow.NumberofSlots} {it.DestinationID}", this, "LightYellow");
                }
            }
            return(packet);
        }