consider the following lab activity:

L2: Industrial Internet of Things (IIoT) system simulation - Versions A and B
Summary

The purpose of this lab is to simulate the operation of a portion of an Industrial Internet of
Things (IIoT), that is modeled as a queuing system, and investigate its performance under
variable configurations, to understand how different scenario configurations and network
parameter settings may affect the system behavior and performance.
Consider the Industry 4.0 scenario. Each machinery component of the production line is equipped with a set of sensors and actuators, that build up an IIoT system.
In particular, a number of sensor devices collect real time monitoring data at the edge of the network, to collect several types of information about the status and the operation of the various production line components. These data can be used, either directly or after some processing, to take decisions and perform specific actions on the production line by means of actuators, in order to manage the system operation, modulate the production system speed, prevent or tackle service interruptions, etc.

More in details, data collected by the sensors are sent to a local Micro Data Center ,
that provides computational capacity close to edge of IIoT network by means of edge nodes, which are managed by an edge controller. edge nodes pre-process data, so that
most requests can be fulfilled locally, whereas only computationally intensive requests are
forwarded to a Cloud data center), thus saving bandwidth and energy. Finally, based
on the data processing output, operative commands are generated and sent to the actuators.
 In case all the edge nodes are busy, incoming data can be buffered, if a buffer is present. However, if the buffer is full or it is not envisioned at all, data packets are
directly forwarded to the Cloud Data Center to perform the entire processing tasks.
In the considered queuing system, the customers represent the IIoT data packets that arrive at that Micro Data Center. The service represents the local processing of the data by edge nodes before generating the actuation message packets or before forwarding data to the Cloud for further computational processing. Finally, the waiting line represents the buffer where packets are stored before performing the computational tasks. Packets that are sent to the Cloud are further processed by Cloud server(s) before generating the actuation message packets that are sent to the actuators. In this case the service is represented by the data processing carried out by the Cloud server(s). Even in the Cloud a buffer may be envisioned.
Two types of data can be generated by the sensor nodes and sent to the Micro Data Center,
each corresponding to a different class of task that can be performed by the actuators:
Class A - High priority tasks: these tasks are delay sensitive, hence implying high priority operations that must be performed on the production line within a strict time deadline. The packets generated by the sensors that are related to high priority tasks (type A packets) typically require a simple processing, that can be locally performed by the edge nodes.

Class B - Low priority tasks: these tasks require more complex computational operations, however the completion of these tasks is not constrained by strict time deadlines, hence
resulting in delay tolerant tasks that can be performed in a longer time period. Due to the
need for more complex computational operations, this type of packets (type B packets), after a local pre-processing at the Micro Data Center level, must be forwarded to the Cloud Data Center to complete the processing.
Denote f the fraction of packets of type B, i.e. the low priority data packets arriving at the Micro Data Center from the sensors that must be further forwarded to the Cloud Data Center after local pre-processing by the edge node(s), due to more complex required computational tasks. In this case, assume a reasonably increased average service time on
the Cloud server(s). Note that, although the required tasks are more complex, the Cloud
Servers are likely to be better performing than the edge nodes.

Furthermore, when data cannot be locally pre-processed due to busy edge nodes and full
buffer, any incoming data (either of type A or B) are forwarded to the Cloud without any
local pre-processing. Since these forwarded data are fully processed in the Cloud, they experience an average service time that reflect the fact that both the simple pre-processing tasks (for type A and type B data) and the more complex computational tasks (only for type B data) are performed in the Cloud Data center itself.

You can include the propagation delay in your analysis, assuming a reasonable additional
delay due to the data transmission from the Micro Data Center to the Cloud Data Center
and for the transmission of the commands from Cloud Data Center to the actuators. The
other propagation delays can be neglected.



Tasks
First task:
 assume a single server with finite buffer for both the Micro Data Center and the Cloud Data Center, with f=0.5. Focusing on the Cloud Data Center sub-system, the packet drop probabil-ity of those data packets that are forwarded to the Cloud for any reason.

1. Observe the system behavior during the warm-up transient period and identify
the transition to the steady state.
2. Try to apply a method to remove the warm-up transient in your simulations.


Second Task:
Consider now the overall system operation, including both the Micro Data Center and
the Cloud Data Center.
1. How does the size of the buffer in the micro Data Center impact on the overall
system performance?
2. Does the size of the buffer in the Cloud Data Center show a similar impact on
the system performance?
3.  How do the characteristics of input data (i.e. different values of f) affect
the overall average queuing delay?

Third Task:
Now define a desired value for the maximum average queuing time of type A packets,
denoted Tq.
1. Assuming again a single-server Micro Data Center and a single-server Cloud Data
Center, replace the edge node with a progressively faster server. Which is the minimum value of the average service rate that is required to reduce the queuing time of type A packets below the threshold Tq?
2. Try to increase the number of edge nodes, assuming the same fixed average service
time for each edge node: which is the minimum number of servers required to
reduce the queuing time below the threshold Tq?

Fourth Task:
Consider a multi-server system, assuming various servers both in the Micro and in the
Cloud Data Centers. Assign an operational cost to each edge node and to the Cloud
servers, with the operational cost for a Cloud server being different with respect to the
one for an edge node. Simulate the system operation over a fixed period of time.
1. Vary the value of f over time, depending on the different time periods within the considered observation window. Investigate how these configuration settings affect the overall system performance.

2. Now assume at least 4 Cloud servers. Furthermore, consider at least three different
types of Cloud servers, each featuring a different service speed and a specific operational cost (that may depend, for example, on the service speed). Test various combinations of server types and investigate the trade off between the overall cost, the queuing delays and the packet drop probability.
3. Set a value of f < 0.5 and define a
desired threshold on the maximum operational cost.
• Identify the best combination of server types allowing to reduce the cost below
the desired threshold.
• Does this combination allow to respect the constraint on the maximum queuing delay, i.e. Tq, set in Task 3 for type A packets?
4. Now, assume to install half the number of Cloud servers, keeping the same value
of f as in Task 4.(c).
• In this case, can you identify the proper configuration of server types allowing
to reduce the cost below the same desired threshold?
• Compare the obtained queueing delay and cost under these two scenarios (i.e.,
N Cloud servers versus N/2 Cloud servers), also highlighting how packets of
type A and packets of type B are differently affected in terms of delay and
packet drop probability.

I want you to gimme the code for simulating the system , the code must have the following specifications:
1. The system must record some metrics about the simulation ( i. average packet delay  ii. packet loss in percent iii. number of arrive A or B packet )
2. It must be able to have single or multiple node servers and cloud servers
3. You must write the code in an understandable way and not too much advanced (Try to comment lines as much as possible)