vlcsim.controller.Connection

class vlcsim.controller.Connection(id: int, receiver: Receiver, time: float)[source]

Bases: object

Represents a data transmission connection in VLC simulation.

Connection objects encapsulate all information about a data transmission session between a receiver device and an access point (AP). Each connection tracks its allocation status, assigned time slices, capacity requirements, and timing information.

The Connection class manages:
  • Unique identification and association with receiver and AP

  • Frame/slice allocation in TDM scheduling

  • Capacity requirements and SNR tracking

  • Connection timing (arrival, goal time, completion)

  • Allocation status (allocated, waiting, refused)

All attributes are private and accessed via properties.

Example

Creating a connection:

receiver = Receiver(x=5.0, y=5.0, z=0.85, aDet=1e-4, ts=0.1,
                  index=1.5, fov=60.0)
connection = Connection(id=0, receiver=receiver, time=0.0)
connection.capacityRequired = 1e6  # 1 Mbps

# Assign to access point
connection.AP = vled
connection.assignFrameSlice(frame=0, slice=3)
__init__(id: int, receiver: Receiver, time: float) None[source]

Initialize a Connection object.

Creates a new connection with specified ID, receiver, and arrival time. The connection is initially marked as allocated but not yet assigned to an AP.

Parameters:
  • id – Connection unique identifier (non-negative integer)

  • receiver – Receiver device for this connection

  • time – Connection arrival time in seconds (non-negative)

Raises:

ValueError – If id or time is negative

Example:

receiver = Receiver(5.0, 5.0, 0.85, 1e-4, 0.1, 1.5, 60.0)
conn = Connection(id=1, receiver=receiver, time=10.5)

Methods

__init__(id, receiver, time)

Initialize a Connection object.

assignFrameSlice(frame, slice)

Assign a specific frame and slice to this connection.

getNextTime()

Get the next transmission start time for this connection.

insertTime(time)

Insert a transmission time into the scheduled times queue.

nextSliceInAPWhenArriving(ap)

Determine the next available slice position when connection arrives.

numberOfSlicesNeeded(capacityRequired, ...)

Calculate the number of TDM slices needed for this connection.

Attributes

AP

Get the Access Point assigned to this connection.

allocated

Check if this connection has been allocated.

capacityRequired

Get the capacity required for this connection.

frameSlice

Get the list of frame/slice assignments for this connection.

goalTime

Get the goal time for this connection.

id

Get the unique identifier of this connection.

receiver

Get the receiver associated with this connection.

snr

Get the Signal-to-Noise Ratio for this connection.

time

Get the arrival time of this connection.

property AP: AccessPoint | None

Get the Access Point assigned to this connection.

Returns:

Access Point used by this connection, or None if not assigned

Return type:

AccessPoint or None

property allocated: bool

Check if this connection has been allocated.

Returns:

True if connection was allocated, False otherwise

Return type:

bool

assignFrameSlice(frame: int, slice: int)[source]

Assign a specific frame and slice to this connection.

Adds a [frame, slice] pair to this connection’s TDM allocation.

Parameters:
  • frame – Frame number to assign

  • slice – Slice number within the frame

Example:

connection.assignFrameSlice(frame=0, slice=3)
connection.assignFrameSlice(frame=1, slice=0)
property capacityRequired: float | None

Get the capacity required for this connection.

Returns:

Required capacity in bits per second (bps), or None if not set

Return type:

float or None

property frameSlice: list[list[int]]

Get the list of frame/slice assignments for this connection.

Returns:

List of [frame, slice] pairs that this connection will use

in TDM scheduling

Return type:

list[list[int]]

Example:

>>> connection.frameSlice
[[0, 3], [0, 7], [1, 2]]
getNextTime() float[source]

Get the next transmission start time for this connection.

Retrieves and removes the next scheduled transmission time from the queue. Used by the simulation event scheduler.

Returns:

Next transmission start time in seconds

Return type:

float

Raises:

IndexError – If no assigned times remain

property goalTime: float | None

Get the goal time for this connection.

The goal time represents the total effective time that the connection will use the channel, calculated based on required and available capacity.

Returns:

Effective transmission time in seconds, or None if not calculated

Return type:

float or None

property id: int

Get the unique identifier of this connection.

Returns:

Connection ID

Return type:

int

insertTime(time: float) None[source]

Insert a transmission time into the scheduled times queue.

Maintains the time queue in chronological order by inserting the new time at the appropriate position. Works with the simulation Future Event List (FEL).

Parameters:

time – Transmission start time in seconds to schedule

Note

Times are maintained in ascending order automatically.

nextSliceInAPWhenArriving(ap: AccessPoint) int[source]

Determine the next available slice position when connection arrives.

Calculates which slice position will be active when this connection arrives, based on the arrival time and AP’s frame structure.

Parameters:

ap – Access Point to check

Returns:

Slice position (0 to ap.slicesInFrame - 1)

Return type:

int

Raises:

ValueError – If AP doesn’t have valid sliceTime or slicesInFrame

Note

Result is computed as: ceil(arrival_time / sliceTime) mod slicesInFrame

numberOfSlicesNeeded(capacityRequired: float, capacityFromAP: float) int[source]

Calculate the number of TDM slices needed for this connection.

Determines how many time slices are required based on the capacity demand and the capacity provided by the access point.

Parameters:
  • capacityRequired – Required data capacity in bps

  • capacityFromAP – Available capacity from AP in bps

Returns:

Number of slices needed (rounded up)

Return type:

int

Raises:

ValueError – If capacityFromAP is zero or negative

Example:

slices = connection.numberOfSlicesNeeded(
    capacityRequired=1e6,  # 1 Mbps
    capacityFromAP=250e3   # 250 kbps per slice
)  # Returns 4 slices
property receiver: Receiver

Get the receiver associated with this connection.

Returns:

The receiver device for this connection

Return type:

Receiver

property snr: float

Get the Signal-to-Noise Ratio for this connection.

Returns:

SNR value (dimensionless), minimum value is sys.float_info.min

Return type:

float

property time: float

Get the arrival time of this connection.

Returns:

Time in seconds when this connection arrived in the simulation

Return type:

float