Beispiel #1
0
 internal void OnHelloReceive(IPHeader ipHeader, OspfHeader ospfHeader, OspfHelloHeader ospfHelloHeader)
 {
     lock (Lock)
     {
         LastSeen = DateTime.Now;
         Log.Write("OSPF", "NEIGHBOR", string.Format("Hello received. From: {0}, State: {1}", ospfHeader.RouterID, OspfNeighborState));
         RaiseEvent(NeighborEventType.HelloReceived);
         if (ospfHelloHeader.Neighbor.Any(p => p == Module.RouterID))
         {
             var tupleData = new Tuple<IPHeader, OspfHeader, Tuple<IPAddress, IPAddress>>(ipHeader, ospfHeader,
                                                                                              new Tuple<IPAddress, IPAddress>(ospfHelloHeader.Dr, ospfHelloHeader.Bdr));
             RaiseEvent(NeighborEventType.TwoWayReceived, tupleData);
         }
         else
         {
             var tupleData = new Tuple<IPHeader, OspfHeader, object>(ipHeader, ospfHeader, ospfHelloHeader);
             RaiseEvent(NeighborEventType.OneWayReceived, tupleData);
         }
     }
 }
Beispiel #2
0
 private void GetSourceAndID(OspfHeader ospfHeader, IPHeader ipHeader, out IPAddress source, out IPAddress id)
 {
     switch (OspfNetworkType)
     {
         case OspfNetworkType.PointToMultiPoint:
         case OspfNetworkType.Broadcast:
         case OspfNetworkType.NBMA:
             source = ipHeader.SourceAddress;
             id = ospfHeader.RouterID;
             break;
         case OspfNetworkType.VirtualLink:
             source = ospfHeader.RouterID;
             id = ospfHeader.RouterID;
             break;
         default:
         case OspfNetworkType.PointToPoint:
             source = ospfHeader.RouterID;
             id = ipHeader.SourceAddress;
             break;
     }
 }
Beispiel #3
0
 internal void OnDBDReceive(IPHeader ipHeader, OspfHeader ospfHeader, Tuple<OspfDbdHeader, OspfLsaHeader[]> dbdHeaderData)
 {
     lock (Lock)
     {
         Log.Write("OSPF", "NEIGHBOR", string.Format("DBD received. From: {0}, State: {1}", ospfHeader.RouterID, OspfNeighborState));
         var tupleData = new Tuple<IPHeader, OspfHeader, Tuple<OspfDbdHeader, OspfLsaHeader[]>>(ipHeader, ospfHeader, dbdHeaderData);
         var ospfDBDHeader = dbdHeaderData.Item1;
         var ospfLsaHeaderArray = (OspfLsaHeader[])dbdHeaderData.Item2;
         switch (OspfNeighborState)
         {
             case OspfNeighborState.Down:
             case OspfNeighborState.Attempt:
                 return;
             case OspfNeighborState.Init:
                 RaiseEvent(NeighborEventType.TwoWayReceived, new Tuple<IPHeader, OspfHeader, Tuple<IPAddress, IPAddress>>(ipHeader, ospfHeader,
                                                                                                                               new Tuple<IPAddress, IPAddress>(DR, BDR)));
                 return;
             case OspfNeighborState.TwoWay:
                 return;
             case OspfNeighborState.ExStart:
                 if (ospfDBDHeader.IsInitial &&
                     ospfDBDHeader.HasMore &&
                     ospfDBDHeader.IsMaster &&
                     (dbdHeaderData.Item2 == null || ospfLsaHeaderArray.Length == 0) &&
                     ospfHeader.RouterID > Module.RouterID)
                 {
                     Log.Write("OSPF", "NEIGHBOR---------EXSTART", "IS SLAVE TO " + ospfHeader.RouterID);
                     LocalMSState = MasterSlaveState.Slave;
                     _dbdPendingAck = null;
                     DDSequenceNumber = ospfDBDHeader.SequenceNumber;
                     LastOspfDBDSeen = ospfDBDHeader;
                     DiscoveredOptions = ospfDBDHeader.OspfOptions;
                     RaiseEvent(NeighborEventType.NegotiationDone);
                     ProcessDBD(tupleData);
                 }
                 else if (!ospfDBDHeader.IsInitial && !ospfDBDHeader.IsMaster &&
                          DDSequenceNumber == dbdHeaderData.Item1.SequenceNumber &&
                          ospfHeader.RouterID < Module.RouterID)
                 {
                     Log.Write("OSPF", "NEIGHBOR---------EXSTART", "IS MASTER OF" + ospfHeader.RouterID);
                     LocalMSState = MasterSlaveState.Master;
                     _dbdPendingAck = null;
                     LastOspfDBDSeen = ospfDBDHeader;
                     DiscoveredOptions = ospfDBDHeader.OspfOptions;
                     RaiseEvent(NeighborEventType.NegotiationDone);
                     ProcessDBD(tupleData);
                 }
                 return;
             case OspfNeighborState.Exchange:
                 //TODO: duplicate check?
                 if (dbdHeaderData.Item1.IsMaster && LocalMSState == MasterSlaveState.Master)
                 {
                     RaiseEvent(NeighborEventType.SeqNumberMismatch,
                                new Tuple<IPHeader, OspfHeader, Tuple<OspfDbdHeader, OspfLsaHeader[]>>(ipHeader, ospfHeader,
                                                                                                             new Tuple<OspfDbdHeader, OspfLsaHeader[]>(ospfDBDHeader, null)));
                     return;
                 }
                 else if (!dbdHeaderData.Item1.IsMaster && LocalMSState == MasterSlaveState.Slave)
                 {
                     RaiseEvent(NeighborEventType.SeqNumberMismatch,
                                new Tuple<IPHeader, OspfHeader, Tuple<OspfDbdHeader, OspfLsaHeader[]>>(ipHeader, ospfHeader,
                                                                                                             new Tuple<OspfDbdHeader, OspfLsaHeader[]>(ospfDBDHeader, null)));
                     return;
                 }
                 else if (dbdHeaderData.Item1.IsInitial)
                 {
                     RaiseEvent(NeighborEventType.SeqNumberMismatch, tupleData);
                     return;
                 }
                 else if (dbdHeaderData.Item1.OspfOptions != DiscoveredOptions)
                 {
                     RaiseEvent(NeighborEventType.SeqNumberMismatch, tupleData);
                     return;
                 }
                 else if ((LocalMSState == MasterSlaveState.Master && dbdHeaderData.Item1.SequenceNumber == DDSequenceNumber) ||
                          (LocalMSState == MasterSlaveState.Slave && dbdHeaderData.Item1.SequenceNumber == DDSequenceNumber + 1))
                 {
                     LastOspfDBDSeen = dbdHeaderData.Item1;
                     ProcessDBD(tupleData);
                     RaiseEvent(NeighborEventType.ExchangeDone);
                     return;
                 }
                 else
                 {
                     RaiseEvent(NeighborEventType.SeqNumberMismatch, tupleData);
                     return;
                 }
             case OspfNeighborState.Loading:
                 break;
             case OspfNeighborState.Full:
                 break;
             default:
                 throw new ArgumentOutOfRangeException();
         }
     }
 }
Beispiel #4
0
 //private void HandleHelloMessage(IPHeader ipHeader, OspfHeader ospfHeader, OspfHelloHeader ospfHelloHeader)
 //{
 //    return;
 //    Neighbor neighbor = NeighborMap[ospfHeader.rid] ?? Neighbor.Create(ipHeader, ospfHeader, ospfHelloHeader);
 //    NeighborEventArgs args = NeighborEventArgs.Create(ipHeader, ospfHeader, ospfHelloHeader);
 //    neighbor.RaiseEvent(NeighborEventType.HelloReceived, args);
 //    if (ospfHelloHeader.neighbor.Any(p => p == RouterID))
 //    {
 //        neighbor.RaiseEvent(NeighborEventType.TwoWayReceived, args);
 //    }
 //    if (neighbor.IsNew && IsPotentialNeighbor(ipHeader, ospfHeader, ospfHelloHeader))
 //    {
 //        NeighborMap.Add(neighbor.RouterId, neighbor);
 //        neighbor.IsNew = false;
 //    }
 //    else
 //    {
 //        Log.Write("OSPF", "HELLO", string.Format("Incompatible OSPF hello message from .", ipHeader.saddr.StandardFormat));
 //    }
 //}
 private bool IsPotentialNeighbor(IPHeader ipHeader, OspfHeader ospfHeader, OspfHelloHeader ospfHelloHeader)
 {
     //if (!ospfHeader.aid.Equals(Area))
     //{
     //    return false;
     //}
     //if (ospfHelloHeader.interval != HelloInterval)
     //{
     //    return false;
     //}
     //if (ospfHelloHeader.routerdeadintvl != RouterDeadInterval)
     //{
     //    return false;
     //}
     //if (((ospfHelloHeader.Options & OspfHelloOptions.ExternalRoutingCapable) == OspfHelloOptions.ExternalRoutingCapable) == IsStub)
     //{
     //    return false;
     //}
     return true;
 }