I have 1000 hosts. I need to simulate the situation when host[0] connects with other 999 hosts by PingApp in accordance with a timetable.
For example
**.host[0]*.numPingApps = 999 #number of hosts
**.host[0]*.pingApp[*].typename = "PingApp"
**.host[0]*.pingApp[*].packetSize = 42 B
**.host[0]*.pingApp[*].sendInterval = 1 s
**.host[0]*.pingApp[*].srcAddr = "host[0]"
**.host[0]*.pingApp[0].destAddr = "host[1]"
**.host[0]*.pingApp[0].startTime = 0 s
**.host[0]*.pingApp[0].stopTime = 5s
**.host[0]*.pingApp[1].destAddr = "host[2]"
**.host[0]*.pingApp[1].startTime = 0.1 s
**.host[0]*.pingApp[1].stopTime = 5.1 s
**.host[0]*.pingApp[2].destAddr = "host[3]"
**.host[0]*.pingApp[2].startTime = 0.2 s
**.host[0]*.pingApp[2].stopTime = 5.2 s
**.host[0]*.pingApp[3].destAddr = "host[4]"
**.host[0]*.pingApp[3].startTime = 0.3 s
**.host[0]*.pingApp[3].stopTime = 5.3 s
and so on...
How can I create the loop for automatic changes of parameters: startTime, stopTime, destAddr, number of pingApp?
I need to increase startTime and stopTime by 0.1s at every step of one point increase of pingApp number and destAddr.
Help me please!
Thank you!
Actually, every host should have only one Ping Application. To achieve your goal you can use the following settings:
**.host[*].numApps = 1
**.host[*].app[0].typename = "PingApp"
**.host[999].app[0].destAddr = "host[0]"
**.host[*].app[0].destAddr = "host[" + string(parentIndex()+1) + "]"
**.host[*].app[0].startTime = replaceUnit (0.1*(parentIndex()), "s")
**.host[*].app[0].stopTime = replaceUnit (5 + 0.1*(parentIndex()), "s")
The paretnIndex() returns the index of the host in vector of hosts, reference OMNeT++ Manual. For the last node (i.e. host[999]) destAddr is set by hand because parentIndex()+1 will return 1000, and there is no host[1000].
The second NED function - replaceUnit() - is used to add the unit to the result of calculation.
Here is an other quasi solution:
From the PingApp's documentation:
string destAddr = default(""); // destination address(es), separated by spaces, "*" means all IPv4/IPv6 interfaces in entire simulation
Specifying '*' allows pinging ALL configured network interfaces in the
whole simulation. This is useful to check if a host can reach ALL other
hosts in the network (i.e. routing tables were set up properly).
To specify the number of ping requests sent to a single destination address,
use the 'count' parameter. After the specified number of ping requests was
sent to a destination address, the application goes to sleep for 'sleepDuration'.
Once the sleep timer has expired, the application switches to the next destination
and starts pinging again. The application stops pinging once all destination
addresses were tested or the simulation time reaches 'stopTime'.
So if you have only these hosts in the network and you don't mind that in the beginning the host pings itself too, destAddr="*" and count=1
I combined answers of #Rudi and #JerzyD. and got the workable solution:
**.host[0]*.numPingApps = 999
**.host[0]*.pingApp[*].typename = "PingApp"
**.host[0]*.pingApp[*].sendInterval = 1 s
**.host[0]*.pingApp[*].packetSize = 42 B
**.host[0]*.pingApp[0..998].destAddr = "host[" + string(index()+1) + "]"
**.host[0]*.pingApp[0..998].startTime = replaceUnit (0.1 * (index()), "s")
**.host[0]*.pingApp[0..998].stopTime = replaceUnit (5 + 0.1 * (index()), "s")
Related
I'm self study of Python and it's my first code.
I'm working for analyze logs from the servers. Usually I need analyze full day logs. I created script (this is example, simple logic) just for check speed. If I use normal coding the duration of analyzing 20mil rows about 12-13 minutes. I need 200mil rows by 5 min.
What I tried:
Use multiprocessing (met issue with share memory, think that fix it). But as the result - 300K rows = 20 sec and no matter how many processes. (PS: Also need control processors count in advance)
Use threading (I found that it's not give any speed, 300K rows = 2 sec. But normal code same, 300K = 2 sec)
Use asyncio (I think that script is slow because need reads many files). Result same as threading - 300K = 2 sec.
Finally I think that all three my script incorrect and didn't work correctly.
PS: I try to avoid use specific python modules (like pandas) because in this case it will be more difficult to execute on different servers. Better to use common lib.
Please help to check 1st - multiprocessing.
import csv
import os
from multiprocessing import Process, Queue, Value, Manager
file = {"hcs.log", "hcs1.log", "hcs2.log", "hcs3.log"}
def argument(m, a, n):
proc_num = os.getpid()
a_temp_m = a["vod_miss"]
a_temp_h = a["vod_hit"]
with open(os.getcwd() + '/' + m, newline='') as hcs_1:
hcs_2 = csv.reader(hcs_1, delimiter=' ')
for j in hcs_2:
if j[3].find('MISS') != -1:
a_temp_m[n] = a_temp_m[n] + 1
elif j[3].find('HIT') != -1:
a_temp_h[n] = a_temp_h[n] + 1
a["vod_miss"][n] = a_temp_m[n]
a["vod_hit"][n] = a_temp_h[n]
if __name__ == '__main__':
procs = []
manager = Manager()
vod_live_cuts = manager.dict()
i = "vod_hit"
ii = "vod_miss"
cpu = 1
n = 1
vod_live_cuts[i] = manager.list([0] * cpu)
vod_live_cuts[ii] = manager.list([0] * cpu)
for m in file:
proc = Process(target=argument, args=(m, vod_live_cuts, (n-1)))
procs.append(proc)
proc.start()
if n >= cpu:
n = 1
proc.join()
else:
n += 1
[proc.join() for proc in procs]
[proc.close() for proc in procs]
I'm expect, each file by def argument will be processed by independent process and finally all results will be saved in dict vod_live_cuts. For each process I added independent list in dict. I think it will help cross operation for use this parameter. But maybe it's wrong way :(
using IPC is costly, so only use "shared objects" for saving the final result, not for intermediate results while parsing the file.
limiting the number of processes is done by using a multiprocessing.Pool, the following code uses it to reach the max hard-disk speed, you only need to post-process the results.
you can only parse data as fast as your HDD can read it (typically 30-80 MB/s), so if you need to improve the performance further you should use SSD or RAID0 for higher disk speed, you cannot get much faster than this without changing your hardware.
import csv
import os
from multiprocessing import Process, Queue, Value, Manager, Pool
file = {"hcs.log", "hcs1.log", "hcs2.log", "hcs3.log"}
def argument(m, a):
proc_num = os.getpid()
a_temp_m_n = 0 # make it local to process
a_temp_h_n = 0 # as shared lists use IPC
with open(os.getcwd() + '/' + m, newline='') as hcs_1:
hcs_2 = csv.reader(hcs_1, delimiter=' ')
for j in hcs_2:
if j[3].find('MISS') != -1:
a_temp_m_n = a_temp_m_n + 1
elif j[3].find('HIT') != -1:
a_temp_h_n = a_temp_h_n + 1
a["vod_miss"].append(a_temp_m_n)
a["vod_hit"].append(a_temp_h_n)
if __name__ == '__main__':
manager = Manager()
vod_live_cuts = manager.dict()
i = "vod_hit"
ii = "vod_miss"
cpu = 1
vod_live_cuts[i] = manager.list()
vod_live_cuts[ii] = manager.list()
with Pool(cpu) as pool:
tasks = []
for m in file:
task = pool.apply_async(argument, args=(m, vod_live_cuts))
tasks.append(task)
for task in tasks:
task.get()
print(list(vod_live_cuts[i]))
print(list(vod_live_cuts[ii]))
I am new to veins and I would like to make DoS attack using flooding technique. I have tried sending a message, that used in case of an accident, say, a million times by a specific car. Is this enough to make a DoS attack? Can I make this code more sophisticated?
void TraCIDemo11p::handlePositionUpdate(cObject* obj) {
BaseWaveApplLayer::handlePositionUpdate(obj);
if (externalID == "2"){ //2 is the attacker
for (int i = 0; i<1000000; i++)
sendMessage(mobility->getRoadId());
}
Note: I am using omnet 5.0, sumo-0.25.0 and veins-4.4, TraCIDemo11p.cc
For the NED File
import inet.applications.dhcp.DhcpServer;
import inet.node.dsdv.DsdvRouter;
import inet.node.inet.AdhocHost;
import inet.node.inet.MulticastRouter;
import inet.node.inet.WirelessHost;
import inet.networklayer.configurator.ipv4.Ipv4NetworkConfigurator;
import inet.node.aodv.AodvRouter;
import inet.node.wireless.AccessPoint;
import inet.physicallayer.ieee80211.packetlevel.Ieee80211ScalarRadioMedium;
import inet.visualizer.integrated.IntegratedVisualizer;
import inet.visualizer.networklayer.NetworkRouteVisualizer;
import inet.visualizer.integrated.IntegratedMultiVisualizer;
import ned.DelayChannel;
network pingattack
{
parameters:
int numhost;
int numattacker;
submodules:
visualizer: IntegratedMultiVisualizer {
#display("p=14,295");
}
configurator: Ipv4NetworkConfigurator {
//config = default(xml("<config><interface WirelessHost='**' address='10.0.0.x' netmask='255.255.255.0'/></config>"));
#display("p=42,430");
}
radioMedium: Ieee80211ScalarRadioMedium {
#display("p=14,339");
}
Attacker[numattacker]: WirelessHost {
#display("p=180,331");
}
Master: WirelessHost {
#display("p=274,316");
}
Slaves[numhost]: WirelessHost {
#display("p=313,247");
}
ap: AccessPoint {
#display("p=244,246");
}
}
For the Ini File,
[General]
description = Displaying Ping Attack
network = pingattack
# Setting up the max area which the modules are able to travel to
# "Z" limits the height. It can only be observed in 3D
**.constraintAreaMinX = 0m
**.constraintAreaMinY = 0m
**.constraintAreaMinZ = 0m
**.updateInterval = 0.1s # test with 0s too, and let getCurrentPosition update the display string from a test module
# Does not specify the intial positions. Random initial position will be chosen within the contraint area,
# unless it is specified in the display string in NED file or initialX,Y,Z
**.mobility.initFromDisplayString = false
# Setting all the default application type to "GlobalArp"
**.arp.typename = "GlobalArp"
# Attacker parameters
*.Attacker[*].numApps = 1 # Number of application layers on attackers
*.Attacker[*].app[0].typename = "PingApp" # Application type for attackers
*.Attacker[*].app[0].destAddr = "Master" # Set ping destination
*.Attacker[*].app[0].startTime = 10s # Initialize start time of ping
# Master Communication
*.Master.numApps = 1 # Number of application layers on master
*.Master.app[0].typename = "PingApp" # Application type for master
# MasterDrone Mobility
*.Master.mobility.typename = "LinearMobility" # Master move at constant speed
*.Master.mobility.speed = 20mps # of 20mps
# Slave Communication
*.Slaves[*].numApps = 1 # Number of application layers on slaves
*.Slaves[*].app[0].typename = "PingApp" # Application type for slaves
*.Slaves[*].app[0].destAddr = "Master" # Set ping destination, to ensure connection with master
*.Slaves[*].app[0].startTime = replaceUnit (0.1*(parentIndex()), "s") # to avoid synchronization
#*.Slaves[*].app[0].sendInterval= 1s # Slaves send ping every 1 second
# Slave mobility
*.Slaves[*].mobility.typename = "MassMobility" # Slaves move randomly
*.Slaves[*].mobility.changeInterval = truncnormal(2s, 0.5s)
*.Slaves[*].mobility.angleDelta = normal(0deg, 30deg)
#*.Slaves[*].mobility.speed = 15mps
# Wlan Config
*.Master.wlan[*].radio.transmitter.power = 10mW # Setting up Master, slaves, attacker wlan transmit power
*.ap.wlan[*].radio.transmitter.power = 100mW
# Pcap recording
**.crcMode = "computed" # To include CRC values in capture files
**.fcsMode = "computed" # To include FCS values in capture files
**.numPcapRecorders = 1 # To include PcapRecordere module
**.pcapRecorder[*].pcapNetwork = 105 # Set PCAP files link-layer header type to 802.11
**.pcapRecorder[*].pcapFile = "results/all.pcap" # Specifying file to write traces in & enable packet capture
**.pcapRecorder[*].verbose = true # To print tcpdump-like textual information to the log (EV)
**.pcapRecorder[*].alwaysFlush = true # Record the packets even if simulation crashes
**.pcapRecorder[*].packetFilter = "ping*"
#Analysis
*.*.wlan[*].**.vector-recording = false
# Visualizer parameters
# Displaying network path activity
*.visualizer.*.numDataLinkVisualizers = 2
*.visualizer.*.numInterfaceTableVisualizers = 2
*.visualizer.*.dataLinkVisualizer[0].displayLinks = true
*.visualizer.*.dataLinkVisualizer[0].packetFilter = "*ping*"
#*.visualizer.*.physicalLinkVisualizer[*].displayLinks = true
#*.visualizer.*.interfaceTableVisualizer[*].displayInterfaceTables = true
#*.visualizer.*.interfaceTableVisualizer[0].format = "%4"
*.visualizer.*.infoVisualizer[0].modules = "*.*.app[0]"
*.visualizer.*.infoVisualizer[1].modules = "*.*.app[1]"
#*.visualizer.*.infoVisualizer[*].format = "%t"
#*.visualizer.*.statisticVisualizer[0].sourceFilter = "**.app[*]"
#*.visualizer.*.statisticVisualizer[0].signalName = "rtt"
#*.visualizer.*.statisticVisualizer[0].unit = "ms"
#*.visualizer.*.infoVisualizer[*].placementHint = "topCenter"
#*.visualizer.*.packetDropVisualizer[*].displayPacketDrops = true
#*.visualizer.*.packetDropVisualizer[*].packetFilter = "ping*"
#*.visualizer.*.packetDropVisualizer[*].labelFormat = "%n/reason: %r"
#*.visualizer.*.packetDropVisualizer[*].fadeOutTime = 3s
#edit
# Set number of Attacker
# Set number of Host
# Set Attacker Ping interval
# Set Transmittion Power of Master Slave Attacker and AP
# Set Max constrain area XYZ
sim-time-limit = 20s
pingattack.numhost = 5
pingattack.numattacker = 1
*.Attacker[*].app[0].sendInterval = 0.0001s
**.constraintAreaMaxX = 2000m
**.constraintAreaMaxY = 2000m
**.constraintAreaMaxZ = 2000m
*.Slaves[*].wlan[*].radio.transmitter.power = 100mW
*.Attacker[*].wlan[*].radio.transmitter.power = 200mW
*.Attacker[*].**.vector-recording = false
*.Slaves[*].mobility.speed = 16mps
Hi I did a DOS Attack using PingApp. I think you can refer to the source code of PingApp. The important part is to have the sendInterval be 0.0001s. Hope this helps!
can any one help me in code of simple ping app
i am trying to ping from 4 nodes but only 2 can communicate in my case
omnet ini code is here
# ping app (host[0] pinged by others)
*.host[0].numPingApps = 0
*.host[*].numPingApps = 4
*.host[1].pingApp[*].destAddr = "host[0]"
*.host[2].pingApp[*].destAddr = "host[0]"
*.host[3].pingApp[*].destAddr = "host[0]"
*.host[4].pingApp[*].destAddr = "host[0]"
*.host[1].pingApp[*].startTime = 3s
*.host[1].pingApp[*].sendInterval = 1s
*.host[1].pingApp[*].srcAddr = "host[1]"
#*.host[1].pingApp[*].destAddr = "host[2]"
*.host[2].pingApp[*].startTime = 2s
*.host[2].pingApp[*].sendInterval = 1s
*.host[2].pingApp[*].srcAddr = "host[2]"
#*.host[2].pingApp[*].destAddr = "host[1]"
*.host[3].pingApp[*].startTime = 1s
*.host[3].pingApp[*].sendInterval = 1s
*.host[3].pingApp[*].srcAddr = "host[3]"
#*.host[3].pingApp[*].destAddr = "host[4]"
Hosts 1, 2, 3, and 4 should have only one pingApp. Moreover, srcAddr may be omitted, because this field will be automatically set by network layer. So minimal omnetpp.ini should look like:
*.host[0].numPingApps = 0
*.host[0].pingApp[0].destAddr = ""
*.host[*].numPingApps = 1
*.host[*].pingApp[0].destAddr = "host[0]"
I will have to admit the title of this question sucks... I couldn't get the best description out. Let me see if I can give an example.
I have about 2700 customers with my software at one time was installed on their server. 1500 or so still do. Basically what I have going on is an Auto Diagnostics to help weed out people who have uninstalled or who have problems with the software for us to assist with. Currently we have a cURL fetching their website for our software and looking for a header return.
We have 8 different statuses that are returned
GREEN - Everything works (usually pretty quick 0.5 - 2 seconds)
RED - Software not found (usually the longest from 5 - 15 seconds)
BLUE - Software found but not activated (usually from 3 - 9 seconds)
YELLOW - Server IP mismatch (usually from 1 - 3 seconds)
ORANGE - Server IP mismatch and wrong software type (usually 5 - 10 seconds)
PURPLE - Activation key incorrect (usually within 2 seconds)
BLACK - Domain returns 404 - No longer exists (usually within a second)
UNK - Connection failed (usually due to our load balancer -- VERY rare) (never countered this yet)
Now basically what happens is a cronJob will start the process by pulling the domain and product type. It will then cURL the domain and start cycling through the status colors above.
While this is happening we have an ajax page that is returning the results so we can keep an eye on the status. The major problem is the Time Remaining is so volatile that it does not do a good estimate. Here is the current math:
# Number of accounts between NOW and when started
$completedAccounts = floor($parseData[2]*($parseData[1]/100));
# Number of seconds between NOW and when started
$completedTime = strtotime("now") - strtotime("$hour:$minute:$second");
# Avg number of seconds per account
$avgPerCompleted = $completedTime / $completedAccounts;
# Total number of remaining accounts to be scanned
$remainingAccounts = $parseData[2] - $completedAccounts;
# The total of seconds remaining for all of the remaining accounts
$remainingSeconds = $remainingAccounts * $avgPerCompleted;
$remainingTime = format_time($remainingSeconds, ":");
I could create a count on all of the green, red, blue, etc... and do an average of how long each color does, then use that for the average time, although I don't believe that would give much better results.
With the difference in times that are so varied, any suggestions would be grateful?
Thanks,
Jeff
OK, I believe I have figured it out. I had to create a class so I could calculate a single regression over a period of time.
function calc() {
$n = count($this->mDatas);
$vSumXX = $vSumXY = $vSumX = $vSumY = 0;
//var_dump($this->mDatas);
$vCnt = 0; // for time-series, start at t=0<br />
foreach ($this->mDatas AS $vOne) {
if (is_array($vOne)) { // x,y pair<br />
list($x,$y) = $vOne;
} else { // time-series<br />
$x = $vCnt; $y = $vOne;
} // fi</p>
$vSumXY += $x*$y;
$vSumXX += $x*$x;
$vSumX += $x;
$vSumY += $y;
$vCnt++;
} // rof
$vTop = ($n*$vSumXY – $vSumX*$vSumY);
$vBottom = ($n*$vSumXX – $vSumX*$vSumX);
$a = $vBottom!=0?$vTop/$vBottom:0;
$b = ($vSumY – $a*$vSumX)/$n;
//var_dump($a,$b);
return array($a,$b);
}
I take each account and start building an array, for the amount of time it takes for each one. The array then runs through this calculation so it will build a x and y time sets. Finally I then run the array through the predict function.
/** given x, return the prediction y */
function calcpredict($x) {
list($a,$b) = $this->calc();
$y = $a*$x+$b;
return $y;
}
I put static values in so you could see the results:
$eachTime = array(7,1,.5,12,11,6,3,.24,.12,.28,2,1,14,8,4,1,.15,1,12,3,8,4,5,8,.3,.2,.4,.6,4,5);
$forecastProcess = new Linear($eachTime);
$forecastTime = $forecastProcess->calcpredict(5);
This overall system gives me about a .003 difference in 10 accounts and about 2.6 difference in 2700 accounts. Next will be to calculate the Accuracy.
Thanks for trying guys and gals
This is the ini file definition that I have:
[General]
network = AQM
**.Nodes = 100 # Numer of Nodes
**.Qmax = 1000 # Buffer Size
**.Qref = 0.25*par("Qmax")
I want that Qref will be 0.25 of the Qmax.
How can I achieve it?
You can name variables and use them afterwards:
[General]
network = AQM
**.Nodes = ${cnt=100} # Numer of Nodes
**.Qmax = 1000 # Buffer Size
**.Qref = 0.25*${cnt}
This even works with ranges or lists:
**.var1 = ${i=0..1 step 0.2}
**.var2 = ${i} * 0.01