// This method only updates the RC on the state of a given SNPP of this router. public void SendRCUpdateSingle(byte beginSNPP) { PeerInformation peer = peers[beginSNPP]; if (peer != null) // There may not be a connection to a router on given SNPP { int capacity = (int)BWMgmt.AvailableBandwidthAt(beginSNPP); LinkStateUpdate message = new LinkStateUpdate( routerId, asId, snId, beginSNPP, peer.remoteRouterId, peer.remoteAsId, peer.remoteSnId, peer.remoteSNPP, capacity ); sendMgmtMessage(rcPort, message); } }
// Method invoked in a separate thread, sets up a UDP listener // that listens for anything on a management port, then detemines // what kind of message it is (with what information) and handles // the response. void ReceiveManagementMsg() { UdpClient listener = new UdpClient(mgmtLocalPort); IPEndPoint groupEP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), mgmtLocalPort); try { while (true) { byte[] bytes = listener.Receive(ref groupEP); Communications.Message msg = Communications.Serialization.Deserialize(bytes); switch (msg.messageType) { case "NHLF.AddUpdateRequest": Log.WriteLine("[MGMT CCI] {1}, port {2}: {0})", msg.messageType, msg.senderID, msg.senderPort); AddUpdateRequest addUpdateReq = (AddUpdateRequest)msg; transportFunction.UpdateRoutingTable(addUpdateReq.entry, true); // !!! IT CAN GO TERRIBLY WRONG HERE !!! SendManagementMsg( (ushort)addUpdateReq.senderPort, new AddUpdateResponse(id, mgmtLocalPort, addUpdateReq.seq, true) ); Log.WriteLine("[MGMT CCI] Add/update forward: conn {2}, iface {0}, label {1}", addUpdateReq.entry.interface_in, addUpdateReq.entry.label_in, addUpdateReq.entry.connectionID); break; case "NHLF.RemoveRequest": Log.WriteLine("[MGMT CCI] {1}, port {2}: {0})", msg.messageType, msg.senderID, msg.senderPort); RemoveRequest removeReq = (RemoveRequest)msg; bool status = transportFunction.RemoveFromRoutingTable(removeReq.connectionID); SendManagementMsg( (ushort)removeReq.senderPort, new RemoveResponse(id, mgmtLocalPort, removeReq.seq, status) ); Log.WriteLine("[MGMT CCI] {0} entries for connection {1}", status ? "Removed" : "Could not remove", removeReq.connectionID); break; case "AllocateRequest": Log.WriteLine("[MGMT LRM] {1}, port {2}: {0})", msg.messageType, msg.senderID, msg.senderPort); AllocateRequest allocateReq = (AllocateRequest)msg; uint label = LRM.AssignBandwidthOnInterface(allocateReq.interfaceID, (uint)allocateReq.bitrate, allocateReq.connectionID); SendManagementMsg( (ushort)allocateReq.senderPort, new AllocateResponse( id, mgmtLocalPort, (int)label, allocateReq.seq ) ); if (label != 0) { Log.WriteLine("[MGMT LRM] Allocate {0} Mb/s on iface {1} for connection {2})", allocateReq.bitrate, allocateReq.interfaceID, allocateReq.connectionID); } else { Log.WriteLine("[MGMT LRM] Could not allocate {0} Mb/s on iface {1} for connection {2})", allocateReq.bitrate, allocateReq.interfaceID, allocateReq.connectionID); } break; case "DeallocateRequest": Log.WriteLine("[MGMT LRM] {1}, port {2}: {0})", msg.messageType, msg.senderID, msg.senderPort); DeallocateRequest deallocateReq = (DeallocateRequest)msg; LRM.ReleaseAsignedBandwidth(deallocateReq.connectionID); SendManagementMsg( (ushort)deallocateReq.senderPort, new DeallocateResponse( id, mgmtLocalPort, deallocateReq.seq ) ); Log.WriteLine("[MGMT LRM] Deallocate resources for connection {0})", deallocateReq.connectionID); break; #if DEBUG case "NHLF.AddUpdateResponse": AddUpdateResponse addUpdateResponse = (AddUpdateResponse)msg; Log.WriteLine("[CCI] AddUpdateRequest for {0} {1}.", addUpdateResponse.senderID, addUpdateResponse.status ? "successful" : "failed"); break; case "NHLF.RemoveResponse": RemoveResponse removeResp = (RemoveResponse)msg; Log.WriteLine("[CCI] Remove {0}", removeResp.status ? "some" : "none"); break; case "LRMRC.LinkStateUpdate": LinkStateUpdate linkStateUpdate = (LinkStateUpdate)msg; Log.WriteLine("[RC] {0} --{2}-> {1}", linkStateUpdate.beginNode.id, linkStateUpdate.endNode.id, linkStateUpdate.capacity); break; #endif default: break; } // NHLFMgmtMessage mgmtMessage = NHLFSerialization.Deserialize(bytes); //NHLFEntry newEntry = mgmtMessage.entry; //string result = transportFunction.UpdateRoutingTable(newEntry, mgmtMessage.addOrSwap); } } catch (Exception e) { Log.WriteLine(e.ToString()); } finally { listener.Close(); } }