本文整理汇总了C#中AdHocBaseApp.Packet.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Packet.Clone方法的具体用法?C# Packet.Clone怎么用?C# Packet.Clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AdHocBaseApp.Packet
的用法示例。
在下文中一共展示了Packet.Clone方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendAODVData
public virtual void SendAODVData(Packet pkg, int dst)
{
Reader node = global.readers[pkg.Prev];
//Check Route Table
double srcCachedTime = -1;
//非强制执行路由发现,则从路由表中找
if (pkg.forceDiscovery == false)
{
RouteEntity entity = GetRouteEntityFromRouteTable(dst, new HashSet<int>(){pkg.Src, pkg.Prev});
if (entity != null)
{
//Console.WriteLine("{0}-{1}", entity.hops, entity.time);
Packet pkg1 = pkg.Clone() as Packet;
pkg1.Prev = Id;
pkg1.Next = entity.next;
pkg1.NextType = pkg.NextType = NodeType.READER;
pkg1.TTL = Math.Max(entity.hops + 1, pkg.TTL);
SendPacketDirectly(scheduler.currentTime, pkg1);
return;
}
}
//Not found...
if (this.routeTable.ContainsKey(dst))
srcCachedTime = this.routeTable[dst].remoteLastUpdatedTime;
Console.WriteLine("{0:F4} [{1}] {2}{3} tries to send {4}{5} but no route", scheduler.currentTime, pkg.Type, this.type, this.Id, pkg.DstType, pkg.Dst);
SendAODVRequest(BroadcastNode.Node, this.Id, dst, pkg.TTL - 1, srcCachedTime, pkg.forceDiscovery);
AddPendingAODVData(pkg);
}
示例2: SendPacketDirectly
public override bool SendPacketDirectly(float time, Packet pkg)
{
float recv_time = 0;
pkg.Prev = Id;
global.PacketSeq++;
if (pkg.Type == PacketType.AODV_REQUEST)
Console.WriteLine("{0:F4} [{1}] {2}{3} sends to {4}{5}({6}->{7}->{8})", time, pkg.Type, this.type, this.Id, pkg.NextType, (pkg.Next == -1 ? "all" : pkg.Next.ToString()), pkg.Src, pkg.Dst, ((AODVRequest)pkg.Data).dst);
else if (pkg.Type == PacketType.AODV_REPLY)
Console.WriteLine("{0:F4} [{1}] {2}{3} sends to {4}{5}({6}->{7}->{8})", time, pkg.Type, this.type, this.Id, pkg.NextType, (pkg.Next == -1 ? "all" : pkg.Next.ToString()), pkg.Src, pkg.Dst, ((AODVReply)pkg.Data).dst);
else
Console.WriteLine("{0:F4} [{1}] {2}{3} sends to {4}{5}({6}->{7})", time, pkg.Type, this.type, this.Id, pkg.NextType, (pkg.Next == -1 ? "all" : pkg.Next.ToString()), pkg.Src, pkg.Dst);
if (pkg.Next == BroadcastNode.Node.Id) //Broadcast
{
List<Reader> list = GetAllNearReaders(global.nodeMaxDist, true);
if (list.Count == 0)
return true;
this.packetCounter++;
if (pkg.seqInited == false) //如果packetSeq小于0,则说明未定该数据包的id
this.packetSeq++;
for (int i = 0; i < list.Count; i++)
{
Packet pkg1 = pkg.Clone() as Packet;
pkg1.DelPacketNode = list[0].Id;
if (pkg1.seqInited == false)
{
pkg1.PrevSenderSeq = this.packetSeq;
if (pkg.Src == Id)
pkg1.SrcSenderSeq = pkg1.PrevSenderSeq;
}
//Console.WriteLine("+packet count: {0}->{1} {2}_{3}", pkg.Prev, pkg.Next, global.readers[pkg.Prev].packetCounter,pkg.PacketSeq);
recv_time = global.processDelay + (float)(Utility.Distance(this, list[i]) / global.lightSpeed);
Event.AddEvent(
new Event(time + recv_time, EventType.RECV, list[i], pkg1));
}
}
else
{
pkg.PrevType = type;
pkg.Prev = Id;
switch (pkg.NextType)
{
case NodeType.READER:
//bool fail = false;
List<Reader> list = GetAllNearReaders(global.nodeMaxDist, true);
Reader nextNode = (Reader)Node.getNode(pkg.Next, NodeType.READER);
if (!list.Contains(global.readers[pkg.Next])) //节点未在区域内,删除该节点,0.2秒后重试
{
Console.WriteLine("{0:F4} [{1}] {2}{3} drop data of {4}{5} due to sending failture.", scheduler.currentTime, pkg.Type, this.type, this.Id, pkg.NextType, pkg.Next);
this.Neighbors.Remove(pkg.Next);
this.routeTable.Remove(pkg.Dst);
if (retryOnSendingFailture == true && (pkg.Type != PacketType.BEACON && pkg.Type != PacketType.AODV_REPLY && pkg.Type != PacketType.AODV_REQUEST))
{
pkg.forceDiscovery = true;
string pkgId = pkg.getId();
if (this.receivedPackets.Contains(pkgId))
this.receivedPackets.Remove(pkgId);
Event.AddEvent(new Event(scheduler.currentTime + 0.2f, EventType.SND_DATA, this, pkg));
Console.WriteLine("retry");
//fail = true;
return false;
}
list.Add(global.readers[pkg.Next]);
}
int totalPackets = 0;
foreach (Reader r in list)
totalPackets += r.packetCounter;
this.packetCounter++;
//Console.WriteLine("+packet count: {0}->{1} {2}_{3}", pkg.Prev, pkg.Next, global.readers[pkg.Prev].packetCounter,pkg.PacketSeq);
double prop = (totalPackets > 90) ? (0.1) : totalPackets / (-100.0) + 1.0;
if (pkg.seqInited == false) //如果packetSeq小于0,则说明未定该数据包的id
this.packetSeq++;
for (int i = 0; i < list.Count; i++)
{
while (true)
{
double ran = Utility.U_Rand(1);
recv_time += global.processDelay;
if (ran < prop)
break;
}
Packet pkg1 = pkg.Clone() as Packet;
if (pkg1.seqInited == false)
{
pkg1.PrevSenderSeq = this.packetSeq;
if (pkg.Src == Id)
pkg1.SrcSenderSeq = pkg1.PrevSenderSeq;
}
//Console.WriteLine("[DEBUG] recv reader{0}-{1}", list[i].id, pkg1.PacketSeq);
recv_time += (float)(Utility.Distance(this, (MobileNode)list[i]) / global.lightSpeed);
/*
if (list[i].id == pkg.Next && fail == false)
//.........这里部分代码省略.........
示例3: RoutePacket
public virtual bool RoutePacket(Packet pkg)
{
Node node;
int dst = pkg.Dst;
InitPacketSeq(pkg);
string pkgId = pkg.getId();
if (global.debug)
Console.WriteLine("[Debug] pkgId:{0}", pkgId);
if (!this.receivedPackets.Contains(pkgId))
this.receivedPackets.Add(pkgId);
else
return true;
if (pkg.PrevType == NodeType.READER)
{
if (pkg.Prev != Id)//itself
{
node = global.readers[pkg.Prev];
if (!Neighbors.ContainsKey(node.Id))
return false;
}
}
else if (pkg.PrevType == NodeType.OBJECT)//from the object.
{
node = global.objects[pkg.Prev];
if (!NearbyObjectCache.ContainsKey(node.Id))
return false;
}
else if (this.IsGateway == false)//Server, Querier, Org or CA
{
return false;
}
// to itself
if (pkg.Dst == Id && pkg.DstType == NodeType.READER)
{
Console.WriteLine("{0:F4} [{1}] {2}{3}->{4}{5}, total: {6}", scheduler.currentTime, "RECV_DATA", pkg.SrcType, pkg.Src, this.type, this.Id, scheduler.currentTime - pkg.beginSentTime);
return true;
}
if (this.IsGateway == false)//the node is not a gateway
{
//to server, then get the nearest gateway.
if (pkg.DstType == NodeType.SERVER || pkg.DstType == NodeType.ORG)
{
if (this.gatewayEntities.Count == 0)
{
Console.WriteLine("{0:F4} [{1}] {2}{3} Drop due to no gateway", scheduler.currentTime, pkg.Type, this.type, this.Id);
return false;
}
GatewayEntity gateway = FindNearestGateway();
//gateway cache? save time
if (global.CheckGatewayCache && gateway != null)
{
Packet pkg1 = pkg.Clone() as Packet;
pkg1.Next = gateway.next;
pkg1.NextType = NodeType.READER;
SendPacketDirectly(scheduler.currentTime, pkg1);
return true;
}
dst = gateway.gateway;
}
}
else //the node is a gateway
{
if (pkg.DstType != NodeType.READER)//To server, object etc
{
//这里需要新增一个数据包,否则在监控现象的时候容易弄错
Packet pkg1 = pkg.Clone() as Packet;
pkg1.Prev = this.Id;
pkg1.PrevType = NodeType.READER;
pkg1.Next = pkg.Dst;
pkg1.NextType = pkg.DstType;
SendPacketDirectly(scheduler.currentTime, pkg1);
return true;
}
}
//have to flood...
SendAODVData(pkg, dst);
return true;
}
示例4: SendPacketDirectly
public override bool SendPacketDirectly(float time, Packet pkg)
{
float recv_time = 0;
pkg.Prev = Id;
Console.WriteLine("{0:F4} [{1}] {2}{3} sends to {4}{5}", scheduler.currentTime, pkg.Type, this.type, this.Id, pkg.NextType, (pkg.Next == -1 ? "all" : pkg.Next.ToString()));
//sentPacketCount和packetSeq是一样的
this.packetSeq++;
this.sentPacketCount++;
if (pkg.Next == -1) //Broadcast
return true;//No such a case.
else
{
pkg.SrcSenderSeq = this.sentPacketCount;
pkg.PrevSenderSeq = this.packetSeq;
MobileNode node = null;
switch (pkg.NextType)
{
case NodeType.READER:
node = global.readers[pkg.Next];
List<Reader> list = GetAllNearReaders(global.objectMaxDist);
if (!list.Contains(node))
list.Add((Reader)node);
for (int i = 0; i < list.Count; i++)
{
Packet pkg1 = pkg.Clone() as Packet;
pkg1.PrevSenderSeq = this.packetSeq;
pkg1.DelPacketNode = list[0].Id;
if (pkg.Src == Id)
pkg1.SrcSenderSeq = this.packetSeq;
node = list[i];
recv_time = global.processDelay + (float)(Utility.Distance(this, node) / global.lightSpeed);
Event.AddEvent(
new Event(time + recv_time, EventType.RECV, node, pkg1));
if (global.debug)
Console.WriteLine("[Debug] object{0} sends to reader{1}", Id, node.Id);
}
break;
default:
Debug.Assert(false, "Error Next Type!");
break;
}
}
return true;
}