/************************************************************************************
* Copyright (C) 2013
*
* TETCOS, Bangalore. India *
* Tetcos owns the intellectual property rights in the Product and its content. *
* The copying, redistribution, reselling or publication of any or all of the *
* Product or its content without express prior written consent of Tetcos is *
* prohibited. Ownership and / or any other right relating to the software and all *
* intellectual property rights therein shall remain at all times with Tetcos. *
* Author: Basamma YB
*
************************************************************************************/
#include "main.h"
#include "WLAN.h"
#include "802_11n_ac.h"
#include "watchdog.h"
/**
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This function is called when MAC_OUT_EVENT trigged when a packet buffer
to process in the MAC layer carrier sense.
It check the Medium, if Medium is BUSY, CS failed return 0.
If Medium is IDLE, packets in the buffer, update arrival time,
add CHECK NAV sub event, return 1 to indicate CS success.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
int fn_NetSim_WLAN_CarrierSense()
{
int nDestPresentFlag;
NETSIM_ID nDeviceId = pstruEventDetails->nDeviceId;
NETSIM_ID nInterfaceId = pstruEventDetails->nInterfaceId;
MAC_VAR *pstruMac = DEVICE_MACVAR(nDeviceId,nInterfaceId);
PHY_VAR *pstruPhy = DEVICE_PHYVAR(nDeviceId,nInterfaceId);
NetSim_PACKET* pstruPacket;
if(pstruMac->Medium != IDLE && pstruMac->CurrentState != MAC_IDLE)// && pstruPhy->RadioState == CHANNEL_IDLE)
return 0; //CS failed
if(pstruMac->pstruTempData)
pstruPacket = pstruMac->pstruTempData;
else
{
pstruPacket = fn_NetSim_WLAN_Packet_GetPacketFromBuffer(pstruMac->pstruQosList,0);
if(!pstruPacket)
return 0; //CS failed
}
//Check the destination is with in the BSS if device is an AP for unicast frames
if(nDeviceId == pstruPhy->nBSSID && pstruPhy->BssType == INFRASTRUCTURE)
{
if(pstruPacket->nDestinationId)
{
nDestPresentFlag = fn_NetSim_WLAN_CheckDestDevicePresentWithinAP(nDeviceId,nInterfaceId,pstruPacket->nDestinationId);
if(!nDestPresentFlag)
{
// Get packet from buffer and move to next packet
pstruPacket = fn_NetSim_WLAN_Packet_GetPacketFromBuffer(pstruMac->pstruQosList,1);
// Drop the packet
fn_NetSim_Packet_FreePacket(pstruPacket);
pstruPacket = NULL;
// If buffer is not NULL add MAC OUT event to process the next packet
pstruPacket = fn_NetSim_WLAN_Packet_GetPacketFromBuffer(pstruMac->pstruQosList,0);
if(!pstruPacket)
return 0; //CS failed
pstruEventDetails->nPacketId = pstruPacket->nPacketId;
if(pstruPacket->pstruAppData)
pstruEventDetails->nSegmentId = pstruPacket->pstruAppData->nSegmentId;
else
pstruEventDetails->nSegmentId = 0;
}
}
}
// Set the Start and Arrival time
if(pstruMac->nRetryCount == 0)
{
if(nDeviceId == pstruPhy->nBSSID && pstruPhy->BssType == INFRASTRUCTURE) // AP
{
pstruPacket->pstruMacData->dArrivalTime = pstruPacket->pstruMacData->dArrivalTime;
}
else // Wireless Nodes
{
pstruPacket->pstruMacData->dArrivalTime = pstruPacket->pstruNetworkData->dEndTime;
}
pstruPacket->pstruMacData->dStartTime = pstruEventDetails->dEventTime;
}
if(pstruMac->nCSFlag == 0)
{
// Add CHECK NAV sub event
//pstruEventDetails->pPacket = pstruPacket;
pstruEventDetails->nPacketId = pstruPacket->nPacketId;
pstruEventDetails->nSubEventType = WLAN_SUBEVENT(CHECK_NAV,pstruEventDetails->nProtocolId);
pstruMac->nCSFlag = 1;
return 1; // CS successfull
}
return 0;
}
/**
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This function called when CHECK_NAV subevent triggered. It is called if the Medium
is IDLE and a packet in the Accessbuffer to transmit.
If NAV <=0 then change the state to Wait_DIFS and add DIFS_END subevent.
If NAV > 0 then change the state to WF_NAV and add NAV_END subevent.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
_declspec(dllexport) int fn_NetSim_WLAN_CheckNAV()
{
NETSIM_ID nDeviceId = pstruEventDetails->nDeviceId;
NETSIM_ID nInterfaceId = pstruEventDetails->nInterfaceId;
NETSIM_ID nProtocolId = pstruEventDetails->nProtocolId;
MAC_VAR *pstruMacVar = DEVICE_MACVAR(nDeviceId,nInterfaceId);
PHY_VAR *pstruPhyVar = DEVICE_PHYVAR(nDeviceId,nInterfaceId);
if(pstruEventDetails->dEventTime >= pstruMacVar->dNAV)
{
// Change the State
fn_NetSim_WLAN_ChangeMacState(pstruMacVar,Wait_DIFS);
// Add DIFS_END subevent
pstruEventDetails->dEventTime = pstruEventDetails->dEventTime + pstruPhyVar->nDIFS;
pstruEventDetails->nSubEventType = WLAN_SUBEVENT(DIFS_END,nProtocolId);
pstruEventDetails->pPacket = NULL;
fnpAddEvent(pstruEventDetails);
}
else
{ // Change the State
fn_NetSim_WLAN_ChangeMacState(pstruMacVar,MAC_IDLE);
pstruMacVar->nCSFlag = 0; // Reset the CS flag
}
return 0;
}
/**
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When the buffer has packet to transmit, the MAC LAYER sense the Medium. If it is IDLE,
then it will wait for DCF Inter Frame Space (DIFS) time before start transmission.
At the end of DIFS time check the Medium. If Medium is IDLE, then change the State
to BACKING_OFF, call the function to start backoff. If Medium is BUSY, then change
the state to IDLE.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
_declspec(dllexport) int fn_NetSim_WLAN_DIFS(fnIncreaseCW fnpIncreaseCW,fnRandomBackOffTimeCalculation fnpRandomBackOffTimeCalculation)
{
NETSIM_ID nDeviceId = pstruEventDetails->nDeviceId;
NETSIM_ID nInterfaceId = pstruEventDetails->nInterfaceId;
MAC_VAR *pstruMac = DEVICE_MACVAR(nDeviceId, nInterfaceId);
// check the medium
if(pstruMac->Medium == IDLE)
{
// Change the state
fn_NetSim_WLAN_ChangeMacState(pstruMac,BACKING_OFF);
// Start Backoff
//pstruMac->BackOffFreezeFlag = 0;
fn_NetSim_WLAN_StartBackOff(fnpIncreaseCW,fnpRandomBackOffTimeCalculation);
}
else
{
fn_NetSim_WLAN_ChangeMacState(pstruMac,MAC_IDLE);
}
pstruMac->nCSFlag = 0; // Reset cs flag
return 0;
}
/**
This function start the Backoff process. If backoff counter != 0,it adds the backoff event at (event
time + backoff time) else it generate the random backoff time and add the backoff event.
*/
int fn_NetSim_WLAN_StartBackOff(fnIncreaseCW fnpIncreaseCW,fnRandomBackOffTimeCalculation fnpRandomBackOffTimeCalculation)
{
NETSIM_ID nDeviceId = pstruEventDetails->nDeviceId;
NETSIM_ID nInterfaceId = pstruEventDetails->nInterfaceId;
NETSIM_ID nProtocolId = pstruEventDetails->nProtocolId;
MAC_VAR *pstruMac = DEVICE_MACVAR(nDeviceId, nInterfaceId);
pstruMac->dBackOffStartTime = pstruEventDetails->dEventTime;
if(pstruMac->dBackOffCounter == 0)
{
if(pstruMac->nRetryCount == 0)
fnpIncreaseCW();// Expand the Contention Window
fnpRandomBackOffTimeCalculation();
}
pstruMac->dBackOffCounter = pstruMac->dBackOffTime;
pstruMac->BackOffFreezeFlag = 0; //Set BackOffFreezFlag as Zero
pstruEventDetails->dEventTime = pstruEventDetails->dEventTime + pstruMac->dBackOffTime;
pstruEventDetails->nEventType = MAC_OUT_EVENT;
pstruEventDetails->nSubEventType = WLAN_SUBEVENT(BACKOFF,nProtocolId);
pstruEventDetails->pPacket = NULL;
fnpAddEvent(pstruEventDetails);
return 0;
}
/**
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This function is used to expand the CW.
If the RetryCount = 0, then CWcurrent is set to CWmin th
没有合适的资源?快使用搜索试试~ 我知道了~
IDS.zip_ns2 code_ns2 ids_project
共155个文件
tlog:60个
c:25个
obj:25个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 76 浏览量
2022-09-19
22:21:13
上传
评论
收藏 677KB ZIP 举报
温馨提示
my project code in ns2
资源推荐
资源详情
资源评论
收起资源包目录
IDS.zip_ns2 code_ns2 ids_project (155个子文件)
802_11_MAC.c.bak 91KB
WLan.c.bak 51KB
DSR.h.bak 39KB
802_11_PHY.c.bak 37KB
WLAN.h.bak 32KB
RouteRequest.c.bak 13KB
802_11e.c.bak 11KB
RouteReply.c.bak 9KB
DSR.c.bak 8KB
RouteError.c.bak 6KB
SendBuffer.c.bak 5KB
Network_Layer_Ack.c.bak 5KB
RouteCache.c.bak 4KB
SourceRoute.c.bak 4KB
WLan.c 52KB
802_11_PHY.c 37KB
802_11ac.c 28KB
802_11n.c 24KB
RouteRequest.c 13KB
802_11ag.c 12KB
802_11e.c 11KB
802_11n_acAggregation.c 10KB
RouteReply.c 9KB
DSR_nodefailure.c 9KB
802_11b.c 8KB
MaintBuffer.c 8KB
DSR.c 8KB
PMD_RX_Specification_802_11abgnac.c 7KB
RouteError.c 7KB
SendBuffer.c 5KB
Malicious.c 5KB
Network_Layer_Ack.c 5KB
Watchdog.c 4KB
RouteCache.c 4KB
SourceRoute.c 4KB
PacketProcessing.c 4KB
Pathrater.c 4KB
CheckRouteFound.c 2KB
802_11_MAC.c 91KB
Intrusion detection system.docx 52KB
DSR.h 39KB
WLAN.h 32KB
802_11abgnac.h 19KB
watchdog.h 2KB
Pathrater.h 2KB
802_11e.h 2KB
802_11n_ac.h 619B
vc100.idb 291KB
vc100.idb 291KB
DSR.lastbuildstate 41B
WLAN.lastbuildstate 41B
DSR.Build.CppClean.log 3KB
DSR.log 2KB
libDSR.Build.CppClean.log 2KB
WLAN.log 2KB
WLAN.Build.CppClean.log 1KB
libDSR.dll.embed.manifest 406B
libWLAN.dll.embed.manifest 406B
libDSR.dll.intermediate.manifest 381B
libWLAN.dll.intermediate.manifest 381B
802_11_MAC.obj 99KB
WLan.obj 75KB
802_11_PHY.obj 74KB
802_11ac.obj 49KB
802_11n.obj 46KB
802_11ag.obj 38KB
RouteRequest.obj 38KB
802_11n_acAggregation.obj 36KB
802_11e.obj 35KB
802_11b.obj 34KB
DSR.obj 34KB
Watchdog.obj 33KB
RouteReply.obj 32KB
MaintBuffer.obj 31KB
RouteError.obj 29KB
SendBuffer.obj 29KB
Network_Layer_Ack.obj 28KB
Pathrater.obj 28KB
RouteCache.obj 27KB
PMD_RX_Specification_802_11abgnac.obj 27KB
Mallicious.obj 26KB
Malicious.obj 26KB
SourceRoute.obj 26KB
PacketProcessing.obj 24KB
CheckRouteFound.obj 21KB
vc100.pdb 108KB
vc100.pdb 100KB
libWLAN_manifest.rc 206B
libDSR_manifest.rc 204B
libDSR.dll.embed.manifest.res 472B
libWLAN.dll.embed.manifest.res 472B
CL.read.1.tlog 189KB
CL.read.1.tlog 150KB
cl.command.1.tlog 9KB
cl.command.1.tlog 7KB
link.read.1.tlog 5KB
link.read.1.tlog 5KB
CL.write.1.tlog 4KB
CL.write.1.tlog 3KB
link.command.1.tlog 3KB
共 155 条
- 1
- 2
资源评论
小贝德罗
- 粉丝: 71
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功