Newer
Older
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <glib.h>
#include <sys/time.h>
#include <ctype.h>
#include <strings.h>
#include <time.h>
#include <math.h>
#include <fcntl.h>
#include <uuid/uuid.h>
#include <errno.h>
#include "pathComp_log.h"
#include "pathComp.h"
#include "pathComp_tools.h"
gint numPathCompIntents = 0; // number of events triggering the path computation
//gint numSuccesPathComp = 0; // number of events resulting in succesfully path computations fulfilling the constraints
struct timeval total_path_comp_time;
gdouble totalReqBw = 0.0;
gdouble totalServedBw = 0.0;
////////////////////////////////////////////////////////////////////////////////////////
/**
* @file pathComp_tools.c
* @brief Function for time processing
*
* @param a
*
* @author Ricardo Martínez <ricardo.martinez@cttc.es>
* @date 2022
*/
////////////////////////////////////////////////////////////////////////////////////////
struct timeval tv_adjust (struct timeval a) {
while (a.tv_usec >= 1000000) {
a.tv_usec -= 1000000;
a.tv_sec++;
}
while (a.tv_usec < 0) {
a.tv_usec += 1000000;
a.tv_sec--;
}
return a;
}
////////////////////////////////////////////////////////////////////////////////////////
/**
* @file pathComp_tools.c
* @brief friendly function to copy safely strings
*
* @param dst
* @param src
*
* @author Ricardo Martínez <ricardo.martinez@cttc.es>
* @date 2022
*/
////////////////////////////////////////////////////////////////////////////////////////
void duplicate_string(gchar* dst, gchar* src) {
g_assert(dst); g_assert(src);
strcpy(dst, src);
dst[strlen(dst)] = '\0';
return;
}
////////////////////////////////////////////////////////////////////////////////////////
/**
* @file pathComp_tools.c
* @brief Function used to print the computed the path
*
* @param path
*
* @author Ricardo Martínez <ricardo.martinez@cttc.es>
* @date 2022
*/
/////////////////////////////////////////////////////////////////////////////////////////
void print_path (struct compRouteOutputItem_t *p) {
g_assert(p);
DEBUG_PC ("=========== COMPUTED PATH =======================");
DEBUG_PC ("E2E Avail. Bw: %f, Latency: %f, Cost: %f, Consumed Power (in W): %f", p->availCap, p->delay, p->cost, p->power);
for (gint k = 0; k < p->numRouteElements; k++) {
DEBUG_PC ("%s[%s] --> %s[%s]", p->routeElement[k].aNodeId.nodeId, p->routeElement[k].aEndPointId,
p->routeElement[k].zNodeId.nodeId, p->routeElement[k].zEndPointId);
DEBUG_PC("\t linkId: %s", p->routeElement[k].linkId);
DEBUG_PC("\t aTopologyId: %s", p->routeElement[k].aTopologyId);
DEBUG_PC("\t zTopologyId: %s", p->routeElement[k].zTopologyId);
}
DEBUG_PC ("==================================================================");
return;
}
////////////////////////////////////////////////////////////////////////////////////////
/**
* @file pathComp_tools.c
* @brief Function used to print the output path formed by link Ids
*
* @param p
*
* @author Ricardo Martínez <ricardo.martinez@cttc.es>
* @date 2022
*/
/////////////////////////////////////////////////////////////////////////////////////////
void print_path_t(struct path_t* p) {
g_assert(p);
DEBUG_PC(" ============ COMPUTED OUTPUT PATH =================");
DEBUG_PC("Path AvailBw: %f, Cost: %f, Latency: %f, Power: %f", p->path_capacity.value,
p->path_cost.cost_value, p->path_latency.fixed_latency, p->path_power.power);
DEBUG_PC("number of links of path %d", p->numPathLinks);
for (gint k = 0; k < p->numPathLinks; k++) {
DEBUG_PC("Link: %s", p->pathLinks[k].linkId);
for (gint l = 0; l < p->pathLinks[k].numLinkTopologies; l++) {
DEBUG_PC("end Link [%d] TopologyId: %s", l, p->pathLinks[k].linkTopologies[l].topologyId);
}
DEBUG_PC(" ContextId: %s", p->pathLinks[k].topologyId.contextId);
DEBUG_PC(" TopologyUUid: %s", p->pathLinks[k].topologyId.topology_uuid);
DEBUG_PC(" aDeviceId: %s", p->pathLinks[k].aDeviceId);
DEBUG_PC(" aEndpointId: %s", p->pathLinks[k].aEndPointId);
}
return;
}
////////////////////////////////////////////////////////////////////////////////////////
/**
* @file pathComp_tools.c
* @brief Function used allocate memory for struct path_t
*
*
* @author Ricardo Martínez <ricardo.martinez@cttc.es>
* @date 2022
*/
////////////////////////////////////////////////////////////////////////////////////////
struct path_t* create_path() {
struct path_t* p = g_malloc0(sizeof(struct path_t));
if (p == NULL) {
DEBUG_PC("Memory allocation failure");
exit(-1);
}
return(p);
}
////////////////////////////////////////////////////////////////////////////////////////
/**
* @file pathComp_tools.c
* @brief Returns the char (36 bytes) format of a uuid
*
* @param uuid
*
* @author Ricardo Martínez <ricardo.martinez@cttc.es>
* @date 2022
*/
/////////////////////////////////////////////////////////////////////////////////////////
gchar* get_uuid_char(uuid_t uuid) {
gchar* uuidChar = g_malloc0(16); // uuid has 36 chars
if (uuidChar == NULL) {
DEBUG_PC("Memory Allocation failure");
exit(-1);
}
uuid_unparse(uuid, (char *)uuidChar);
return uuidChar;
}
////////////////////////////////////////////////////////////////////////////////////////
/**
* @file pathComp_tools.c
* @brief Makes a copy of the service identifier (including the context)
*
* @param o
* @param i
*
* @author Ricardo Martínez <ricardo.martinez@cttc.es>
* @date 2022
*/
/////////////////////////////////////////////////////////////////////////////////////////
void copy_service_id(struct serviceId_t* o, struct serviceId_t* i) {
g_assert(o); g_assert(i);
memcpy(o->contextId, i->contextId, sizeof(i->contextId));
memcpy(o->service_uuid, i->service_uuid, sizeof(i->service_uuid));
Loading
Loading full blame...