Skip to content

vGateway

The class "vGateway" is a unique implementation of the "PhysicalEntity" class. Unlike other entities, the "vGateway" does not possess a "vCPU", RAM, or ROM. Its primary role is to function as the entry point for the cloud environment, serving as the central hub for incoming and outgoing user traffic.

The "vGateway" inherits all the member functions implemented for the "vSwitch" class, allowing it to perform routing and switching operations. However, unlike other entities, the "vGateway" does not create a simulated process for packet decoding upon receiving simulated packets.

Additionally, the "vGateway" is designed to be linked exclusively with "vRouter" instances, facilitating seamless connectivity and routing between the gateway and the routers within the simulated network topology.

Bases: Entity

Source code in PyCloudSim\entity\v_gateway.py
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
class vGateway(Entity):
    def __init__(
        self,
        label: str | None = None,
    ) -> None:
        """Create a virtual gateway.

        Args:
            label (str | None, optional): short description of the gateway. Defaults to None.
        """
        super().__init__(label=label, create_at=0)

        self._users: List[vUser] = EntityList()
        self._NIC = vNIC(host=self, label=f"{self}-NIC")
        self._ram = Resource(capacity=inf, label=f"{self}-RAM")
        self._cpu = None

    def on_creation(self):
        simulation.topology.add_node(self)
        self.NIC.create(simulation.now)
        self.NIC.power_on(simulation.now)

    def on_termination(self):
        return super().on_termination()

    def on_destruction(self):
        return super().on_destruction()

    def receive_packet(self, packet: vPacket) -> None:
        """Receive a packet from the NIC."""
        if packet.decoded:
            packet.state.remove(Constants.DECODED)
        if packet.in_transmission:
            packet.state.remove(Constants.INTRANSMISSION)
        try:
            packet.get(self.ram, packet.size)
        except:
            packet.drop()
            return
        self.packet_queue.append(packet)
        packet._current_hop = self
        if packet.current_hop is not packet.dst_host:
            packet._next_hop = packet.path[indexOf(packet.path, self) + 1]
        else:
            packet.success(simulation.now)
        logger.info(f"{simulation.now}:\t{self} receives {packet}.")

    @property
    def users(self) -> List[vUser]:
        """Returns the users asscociated with the gateway."""
        return self._users

    @property
    def NIC(self) -> vNIC:
        """Return the NIC of this virtual gateway."""
        return self._NIC

    @property
    def ram(self) -> Resource:
        """Return the RAM of the virtual gateway which has infinite capacity."""""
        return self._ram

    @property
    def cpu(self):
        """Return the CPU of the virtual gateway which is none, created for avoid typing issues."""
        return self._cpu

    @property
    def packet_queue(self):
        """Return the packet queue of the hardware entity"""
        return self.NIC.packet_queue

NIC: vNIC property

Return the NIC of this virtual gateway.

cpu property

Return the CPU of the virtual gateway which is none, created for avoid typing issues.

packet_queue property

Return the packet queue of the hardware entity

ram: Resource property

Return the RAM of the virtual gateway which has infinite capacity.

users: List[vUser] property

Returns the users asscociated with the gateway.

__init__(label=None)

Create a virtual gateway.

Parameters:

Name Type Description Default
label str | None

short description of the gateway. Defaults to None.

None
Source code in PyCloudSim\entity\v_gateway.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def __init__(
    self,
    label: str | None = None,
) -> None:
    """Create a virtual gateway.

    Args:
        label (str | None, optional): short description of the gateway. Defaults to None.
    """
    super().__init__(label=label, create_at=0)

    self._users: List[vUser] = EntityList()
    self._NIC = vNIC(host=self, label=f"{self}-NIC")
    self._ram = Resource(capacity=inf, label=f"{self}-RAM")
    self._cpu = None

receive_packet(packet)

Receive a packet from the NIC.

Source code in PyCloudSim\entity\v_gateway.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def receive_packet(self, packet: vPacket) -> None:
    """Receive a packet from the NIC."""
    if packet.decoded:
        packet.state.remove(Constants.DECODED)
    if packet.in_transmission:
        packet.state.remove(Constants.INTRANSMISSION)
    try:
        packet.get(self.ram, packet.size)
    except:
        packet.drop()
        return
    self.packet_queue.append(packet)
    packet._current_hop = self
    if packet.current_hop is not packet.dst_host:
        packet._next_hop = packet.path[indexOf(packet.path, self) + 1]
    else:
        packet.success(simulation.now)
    logger.info(f"{simulation.now}:\t{self} receives {packet}.")