-
Notifications
You must be signed in to change notification settings - Fork 0
/
read-CSV-front.py
149 lines (131 loc) · 5.64 KB
/
read-CSV-front.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# MIT License
# Copyright (c) 2023 Ericsson Research
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
##################################################################
# Author: Shilpa Budhkar
# Dated: 3 Feb 2023
# Module Name: Microservice Model Generator
# Copyright Ericsson 2023
##################################################################
# importing the module
import csv
import zulu
import pandas as pd
import numpy
from datetime import timedelta
#creating a csv of unique source and destination list
#-----------------------------------------------------------------------------------------------------------------------------------------
# open the file in read mode
filename = open('frontend-cluster-1.csv', 'r')
# creating dictreader object
file = csv.DictReader(filename)
# creating empty lists
source = []
dest = []
# iterating over each row and append
# values to empty list
for col in file:
source.append(col['downstream_pod_ip'])
dest.append(col['upstream_pod_ip'])
#totalunit.append(col['total_units'])
# printing lists
# print('Source:', source)
# print('Destination:', dest)
dict = {'SourceIP': source, 'DestinationIP': dest}
df = pd.DataFrame(dict)
uniq= df.drop_duplicates()
uniq.to_csv('dependency-f1.csv')
#----------------------------------------------------------------------------------------------------------------------------------------
#Function to Change time into seconds for frequency calculation
def get_seconds(time_str):
#print('Time in hh:mm:ss:', time_str)
# split in hh, mm, ss
hh, mm, ss = time_str.split(':')
return float(hh) * 3600 + float(mm) * 60 + float(ss)
#Data Frame to Read source desti IP from dependecny.csv and retrieving parameters for corresponding IP pair from traces
sd = pd.read_csv('dependency-f1.csv')
sdtrace = pd.read_csv("frontend-cluster-1.csv", usecols=["timestamp","duration","bytes_sent","bytes_received","downstream_pod_ip","upstream_pod_ip"])
#create empty time and other paramters list
timecount = []
allPairFreq = []
bandlist1 = []
bandlist2 = []
rtdlist = []
allPairBand = []
allPairRTD = []
for i in sd.index:
x1 = sd['SourceIP'][i]
y1 = sd['DestinationIP'][i]
# print (x1)
# print (y1)
for j in sdtrace.index:
x2 = sdtrace['downstream_pod_ip'][j]
y2 = sdtrace['upstream_pod_ip'][j]
# print (x2)
# print (y2)
if ((x1== x2) and (y1==y2)):
# print("source and dest match")
timecount.append(sdtrace['timestamp'][j]) # create a list of all time stamps for IP Pair
bandlist1.append(sdtrace['bytes_sent'][j])
bandlist2.append(sdtrace['bytes_received'][j])
rtdlist.append(sdtrace['duration'][j])
#-----------------------------------------------------------------------------------------------------------------------
#Caclulate frequency for no of messages per second
t1 = 0
t2 = 0
count =0
t1 = zulu.parse(timecount[0])
k1 = 0
freq = []
for k in timecount:
t2= zulu.parse(timecount[k1])
temp = get_seconds(str(t2-t1))
if temp < 1:
count =count+1
# print("time difference not one now = ", get_seconds(str(t2-t1)))
else:
# print("time difference is one now = ", get_seconds(str(t2-t1)), " and count is ", count)
freq.append(count) # add no. of messages exchange within 1 sec in freq list
count =0 # resent counter for another second
t1 = zulu.parse(timecount[k1]) # reset start point to count frequency
k1 = k1+1
freq.append(count) # add last no. of messages exchange within 1 sec in freq list
# print("Freq list is ", freq)
# print("Average of the freq is ", numpy.average(freq))
#add average freq to allPairFreq
allPairFreq.append(round(numpy.average(freq)))
freq.clear() # reset freq for another IP pair
timecount.clear() # reset timecount list for another IP pair
#---------------------------------------------------------------------------------------------------------------------------------------
#calculate bandwdth consumption in no. of bytes
# print(bandlist1, " Average is ", numpy.average(bandlist1))
# print(bandlist2, " Average is ", numpy.average(bandlist2))
B = (numpy.average(bandlist1) + numpy.average(bandlist2))/2
allPairBand.append(round(B))
# print("Average bandwith usage is ", B)
bandlist1.clear()
bandlist2.clear()
#---------------------------------------------------------------------------------------------------------------------------------------
#calculate average of round trip delay in milliseconds
allPairRTD.append(round(numpy.average(rtdlist)))
rtdlist.clear() # reset freq for another IP pair
#add allPairFreq to csv
addcol = pd.read_csv('dependency-f1.csv')
addcol['Frequency'] = allPairFreq
addcol['Bandwidth_C'] = allPairBand
addcol['RT_Delay'] = allPairRTD
addcol.to_csv("dependency-f1.csv",index=False)