|
INET Framework for OMNeT++/OMNEST
|
00001 // 00002 // Copyright (C) 2006 Andras Babos and Andras Varga 00003 // 00004 // This program is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public License 00006 // as published by the Free Software Foundation; either version 2 00007 // of the License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU Lesser General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU Lesser General Public License 00015 // along with this program; if not, see <http://www.gnu.org/licenses/>. 00016 // 00017 00018 #include "OSPFInterfaceStateDown.h" 00019 #include "MessageHandler.h" 00020 #include "OSPFArea.h" 00021 #include "OSPFRouter.h" 00022 #include "OSPFInterfaceStatePointToPoint.h" 00023 #include "OSPFInterfaceStateNotDesignatedRouter.h" 00024 #include "OSPFInterfaceStateWaiting.h" 00025 #include "OSPFInterfaceStateLoopback.h" 00026 00027 void OSPF::InterfaceStateDown::ProcessEvent(OSPF::Interface* intf, OSPF::Interface::InterfaceEventType event) 00028 { 00029 if (event == OSPF::Interface::InterfaceUp) { 00030 OSPF::MessageHandler* messageHandler = intf->GetArea()->GetRouter()->GetMessageHandler(); 00031 messageHandler->StartTimer(intf->GetHelloTimer(), truncnormal(0.1, 0.01)); // add some deviation to avoid startup collisions 00032 messageHandler->StartTimer(intf->GetAcknowledgementTimer(), intf->GetAcknowledgementDelay()); 00033 switch (intf->GetType()) { 00034 case OSPF::Interface::PointToPoint: 00035 case OSPF::Interface::PointToMultiPoint: 00036 case OSPF::Interface::Virtual: 00037 ChangeState(intf, new OSPF::InterfaceStatePointToPoint, this); 00038 break; 00039 00040 case OSPF::Interface::NBMA: 00041 if (intf->GetRouterPriority() == 0) { 00042 ChangeState(intf, new OSPF::InterfaceStateNotDesignatedRouter, this); 00043 } else { 00044 ChangeState(intf, new OSPF::InterfaceStateWaiting, this); 00045 messageHandler->StartTimer(intf->GetWaitTimer(), intf->GetRouterDeadInterval()); 00046 00047 long neighborCount = intf->GetNeighborCount(); 00048 for (long i = 0; i < neighborCount; i++) { 00049 OSPF::Neighbor* neighbor = intf->GetNeighbor(i); 00050 if (neighbor->GetPriority() > 0) { 00051 neighbor->ProcessEvent(OSPF::Neighbor::Start); 00052 } 00053 } 00054 } 00055 break; 00056 00057 case OSPF::Interface::Broadcast: 00058 if (intf->GetRouterPriority() == 0) { 00059 ChangeState(intf, new OSPF::InterfaceStateNotDesignatedRouter, this); 00060 } else { 00061 ChangeState(intf, new OSPF::InterfaceStateWaiting, this); 00062 messageHandler->StartTimer(intf->GetWaitTimer(), intf->GetRouterDeadInterval()); 00063 } 00064 break; 00065 00066 default: 00067 break; 00068 } 00069 } 00070 if (event == OSPF::Interface::LoopIndication) { 00071 intf->Reset(); 00072 ChangeState(intf, new OSPF::InterfaceStateLoopback, this); 00073 } 00074 } 00075