public static byte[] GetBytes(RipDataHeader ripDataHeader) { var list = new List<byte>(); list.AddRange(ByteReader.GetBytes(ripDataHeader.AddressFamily)); list.AddRange(ByteReader.GetBytes(ripDataHeader.RouteTag)); list.AddRange(ripDataHeader.Network.GetBytes()); list.AddRange(ripDataHeader.Mask.GetBytes()); list.AddRange(ripDataHeader.NextHop.GetBytes()); list.AddRange(ByteReader.GetBytes(ripDataHeader.Metric)); return list.ToArray(); }
private void HandleRequest(string deviceID, RipPreambleHeader ripPreambleHeader, RipDataHeader[] ripDataHeaderArray) { //TODO: does rip flood to all interfaces upon requst from one?? SendFlood(deviceID); }
private void HandleResponse(string deviceID, RipPreambleHeader ripPreambleHeader, RipDataHeader[] ripDataHeaderArray, IPHeader ipHeader) { foreach (RipDataHeader ripDataHeader in ripDataHeaderArray) { if (RipDatabase.ContainsKey(ripDataHeader.Network)) { RipRoute route = RipDatabase[ripDataHeader.Network]; if (ripDataHeader.Metric < route.Metric) { RipDatabase[ripDataHeader.Network].UpdateRipHeaderData(ipHeader.SourceAddress, ripDataHeader); } else if (ripDataHeader.Metric > route.Metric && ripDataHeader.NextHop == ipHeader.SourceAddress) { if (route.AcceptPotentialNewMetricOnNextSighting && route.PotentialNewMetric == ripDataHeader.Metric) { route.AcceptPotentialNewMetric(); } else { route.BeginHoldDownTime(ripDataHeader); } } route.TimeUpdated = DateTime.Now; route.RaiseEvent(RipEvent.Sighted); } else { RipRoute route = RipRoute.Create(ipHeader.SourceAddress, ripDataHeader, deviceID); route.GCCollect += (s, e) => { RipDatabase.Remove((s as RipRoute).Network); Controller.RemoveRoute(this, route); }; Log.Write("RIP", "RipDatabaseAdd", ripDataHeader.Network.StandardFormat); RipDatabase.Add(ripDataHeader.Network, route); Controller.RegisterRoute(this, route); } } }