Documentation ¶
Overview ¶
Package simulator contains the core simulation coordinator
Package simulator contains the core simulation coordinator
Index ¶
- func ExtractDeviceID(id simapi.PortID) (simapi.DeviceID, error)
- type ConnectionTracker
- type DeviceAgent
- type DeviceSimulator
- func (ds *DeviceSimulator) AddStreamResponder(responder StreamResponder)
- func (ds *DeviceSimulator) AddSubscribeResponder(responder SubscribeResponder)
- func (ds *DeviceSimulator) Counters() *entries.Counters
- func (ds *DeviceSimulator) DisablePort(id simapi.PortID, mode simapi.StopMode) error
- func (ds *DeviceSimulator) EnablePort(id simapi.PortID) error
- func (ds *DeviceSimulator) GetPipelineConfig() *p4api.ForwardingPipelineConfig
- func (ds *DeviceSimulator) HasPuntRuleForEthType(ethType layers.EthernetType) (uint32, bool)
- func (ds *DeviceSimulator) IsMaster(chassisID uint64, role string, electionID *p4api.Uint128) error
- func (ds *DeviceSimulator) Meters() *entries.Meters
- func (ds *DeviceSimulator) ProcessConfigGet(prefix *gnmi.Path, paths []*gnmi.Path) ([]*gnmi.Notification, error)
- func (ds *DeviceSimulator) ProcessConfigSet(prefix *gnmi.Path, updates []*gnmi.Update, replacements []*gnmi.Update, ...) ([]*gnmi.UpdateResult, error)
- func (ds *DeviceSimulator) ProcessDigestAck(ack *p4api.DigestListAck, responder StreamResponder) error
- func (ds *DeviceSimulator) ProcessPacketOut(packetOut *p4api.PacketOut, responder StreamResponder) error
- func (ds *DeviceSimulator) ProcessRead(requests []*p4api.Entity, sender entries.BatchSender) []error
- func (ds *DeviceSimulator) ProcessWrite(atomicity p4api.WriteRequest_Atomicity, updates []*p4api.Update) error
- func (ds *DeviceSimulator) RecordRoleElection(role *p4api.Role, electionID *p4api.Uint128) *p4api.Uint128
- func (ds *DeviceSimulator) RefreshConfig()
- func (ds *DeviceSimulator) RemoveStreamResponder(responder StreamResponder)
- func (ds *DeviceSimulator) RemoveSubscribeResponder(responder SubscribeResponder)
- func (ds *DeviceSimulator) RunMastershipArbitration(role *p4api.Role, electionID *p4api.Uint128) error
- func (ds *DeviceSimulator) SendPacketIn(packet []byte, md *p4utils.PacketInMetadata)
- func (ds *DeviceSimulator) SendToAllResponders(response *p4api.StreamMessageResponse)
- func (ds *DeviceSimulator) SetPipelineConfig(fpc *p4api.ForwardingPipelineConfig) error
- func (ds *DeviceSimulator) SnapshotStats() *DeviceSimulator
- func (ds *DeviceSimulator) Start(simulation *Simulation) error
- func (ds *DeviceSimulator) Stop(mode simapi.StopMode)
- func (ds *DeviceSimulator) Tables() *entries.Tables
- func (ds *DeviceSimulator) UpdateConfig()
- func (ds *DeviceSimulator) UpdateIOStats(byteCount int, input bool)
- type HostSimulator
- func (hs *HostSimulator) EmitARPRequests(nic *simapi.NetworkInterface, dstIPs []string) error
- func (hs *HostSimulator) GetNetworkInterfaceByMac(mac string) *simapi.NetworkInterface
- func (hs *HostSimulator) GetRandomNetworkInterface() *simapi.NetworkInterface
- func (hs *HostSimulator) SendARPRequest(another *simapi.NetworkInterface)
- func (hs *HostSimulator) SendARPResponse(another *simapi.Host)
- func (hs *HostSimulator) Start()
- func (hs *HostSimulator) Stop()
- type IOStats
- type LinkSimulator
- type Simulation
- func (s *Simulation) AddDeviceSimulator(dev *simapi.Device, agent DeviceAgent) (*DeviceSimulator, error)
- func (s *Simulation) AddHostSimulator(host *simapi.Host) (*HostSimulator, error)
- func (s *Simulation) AddLinkSimulator(link *simapi.Link) (*LinkSimulator, error)
- func (s *Simulation) EmitARPs(id simapi.HostID, mac string, ips []string) error
- func (s *Simulation) GetDeviceSimulator(id simapi.DeviceID) (*DeviceSimulator, error)
- func (s *Simulation) GetDeviceSimulatorForPort(id simapi.PortID) (*DeviceSimulator, error)
- func (s *Simulation) GetDeviceSimulators() []*DeviceSimulator
- func (s *Simulation) GetHostSimulator(id simapi.HostID) (*HostSimulator, error)
- func (s *Simulation) GetHostSimulators() []*HostSimulator
- func (s *Simulation) GetLinkFromPort(portID simapi.PortID) *simapi.Link
- func (s *Simulation) GetLinkSimulator(id simapi.LinkID) (*LinkSimulator, error)
- func (s *Simulation) GetLinkSimulators() []*LinkSimulator
- func (s *Simulation) GetRandomHostSimulator(except *HostSimulator) *HostSimulator
- func (s *Simulation) RemoveDeviceSimulator(id simapi.DeviceID) error
- func (s *Simulation) RemoveHostSimulator(id simapi.HostID) error
- func (s *Simulation) RemoveLinkSimulator(id simapi.LinkID) error
- type StatsCollector
- type StreamResponder
- type SubscribeResponder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConnectionTracker ¶ added in v0.1.7
type ConnectionTracker interface { // GetConnection returns the peer connection information GetConnection() *misc.Connection }
ConnectionTracker is an abstraction of an entity maintaining a peer connection
type DeviceAgent ¶
type DeviceAgent interface { // Start starts the simulated device agent Start(simulation *Simulation, deviceSim *DeviceSimulator) error // Stop stops the simulated device agent Stop(mode simapi.StopMode) error }
DeviceAgent is an abstraction of P4Runtime and gNMI NB server
type DeviceSimulator ¶
type DeviceSimulator struct { configtree.Configurable configtree.GNMIConfigurable Device *simapi.Device Ports map[simapi.PortID]*simapi.Port Agent DeviceAgent // contains filtered or unexported fields }
DeviceSimulator simulates a single device
func NewDeviceSimulator ¶
func NewDeviceSimulator(device *simapi.Device, agent DeviceAgent, simulation *Simulation) *DeviceSimulator
NewDeviceSimulator initializes a new device simulator
func (*DeviceSimulator) AddStreamResponder ¶
func (ds *DeviceSimulator) AddStreamResponder(responder StreamResponder)
AddStreamResponder adds the given stream responder to the specified device
func (*DeviceSimulator) AddSubscribeResponder ¶
func (ds *DeviceSimulator) AddSubscribeResponder(responder SubscribeResponder)
AddSubscribeResponder adds the given subscribe responder to the specified device
func (*DeviceSimulator) Counters ¶
func (ds *DeviceSimulator) Counters() *entries.Counters
Counters returns the device counters store
func (*DeviceSimulator) DisablePort ¶
DisablePort disables the specified simulated device port
func (*DeviceSimulator) EnablePort ¶
func (ds *DeviceSimulator) EnablePort(id simapi.PortID) error
EnablePort enables the specified simulated device port
func (*DeviceSimulator) GetPipelineConfig ¶
func (ds *DeviceSimulator) GetPipelineConfig() *p4api.ForwardingPipelineConfig
GetPipelineConfig returns a copy of the forwarding pipeline configuration for the device
func (*DeviceSimulator) HasPuntRuleForEthType ¶ added in v0.1.2
func (ds *DeviceSimulator) HasPuntRuleForEthType(ethType layers.EthernetType) (uint32, bool)
HasPuntRuleForEthType returns true if the device has a table with punt-to-CPU action installed in one of its tables
func (*DeviceSimulator) IsMaster ¶
IsMaster returns an error if the given election ID is not the master for the specified device (chassis) and role.
func (*DeviceSimulator) Meters ¶
func (ds *DeviceSimulator) Meters() *entries.Meters
Meters returns the device meters store
func (*DeviceSimulator) ProcessConfigGet ¶
func (ds *DeviceSimulator) ProcessConfigGet(prefix *gnmi.Path, paths []*gnmi.Path) ([]*gnmi.Notification, error)
ProcessConfigGet handles the configuration get request
func (*DeviceSimulator) ProcessConfigSet ¶
func (ds *DeviceSimulator) ProcessConfigSet(prefix *gnmi.Path, updates []*gnmi.Update, replacements []*gnmi.Update, deletes []*gnmi.Path) ([]*gnmi.UpdateResult, error)
ProcessConfigSet handles the configuration set request
func (*DeviceSimulator) ProcessDigestAck ¶
func (ds *DeviceSimulator) ProcessDigestAck(ack *p4api.DigestListAck, responder StreamResponder) error
ProcessDigestAck handles the specified digest list ack message
func (*DeviceSimulator) ProcessPacketOut ¶
func (ds *DeviceSimulator) ProcessPacketOut(packetOut *p4api.PacketOut, responder StreamResponder) error
ProcessPacketOut handles the specified packet out message
func (*DeviceSimulator) ProcessRead ¶
func (ds *DeviceSimulator) ProcessRead(requests []*p4api.Entity, sender entries.BatchSender) []error
ProcessRead executes the read of the specified set of requests, returning accumulated results via the supplied sender
func (*DeviceSimulator) ProcessWrite ¶
func (ds *DeviceSimulator) ProcessWrite(atomicity p4api.WriteRequest_Atomicity, updates []*p4api.Update) error
ProcessWrite processes the specified batch of updates
func (*DeviceSimulator) RecordRoleElection ¶
func (ds *DeviceSimulator) RecordRoleElection(role *p4api.Role, electionID *p4api.Uint128) *p4api.Uint128
RecordRoleElection checks the given election ID for the specified role and records it if the given election ID is larger than a previously recorded election ID for the same role; returns the winning election ID for the role or nil if a master for this role and election ID is already claimed
func (*DeviceSimulator) RefreshConfig ¶ added in v0.1.20
func (ds *DeviceSimulator) RefreshConfig()
RefreshConfig refreshes the config tree state from any relevant external source state
func (*DeviceSimulator) RemoveStreamResponder ¶
func (ds *DeviceSimulator) RemoveStreamResponder(responder StreamResponder)
RemoveStreamResponder removes the specified stream responder from the specified device
func (*DeviceSimulator) RemoveSubscribeResponder ¶
func (ds *DeviceSimulator) RemoveSubscribeResponder(responder SubscribeResponder)
RemoveSubscribeResponder removes the specified subscribe responder from the specified device
func (*DeviceSimulator) RunMastershipArbitration ¶
func (ds *DeviceSimulator) RunMastershipArbitration(role *p4api.Role, electionID *p4api.Uint128) error
RunMastershipArbitration processes the specified arbitration update
func (*DeviceSimulator) SendPacketIn ¶
func (ds *DeviceSimulator) SendPacketIn(packet []byte, md *p4utils.PacketInMetadata)
SendPacketIn emits packet in with the specified packet payload and ingress port metadata, to all current responders (streams) associated with this device
func (*DeviceSimulator) SendToAllResponders ¶
func (ds *DeviceSimulator) SendToAllResponders(response *p4api.StreamMessageResponse)
SendToAllResponders sends the specified message to all responders
func (*DeviceSimulator) SetPipelineConfig ¶
func (ds *DeviceSimulator) SetPipelineConfig(fpc *p4api.ForwardingPipelineConfig) error
SetPipelineConfig sets the forwarding pipeline configuration for the device
func (*DeviceSimulator) SnapshotStats ¶
func (ds *DeviceSimulator) SnapshotStats() *DeviceSimulator
SnapshotStats snapshots any dynamic device stats, e.g. pipeline info
func (*DeviceSimulator) Start ¶
func (ds *DeviceSimulator) Start(simulation *Simulation) error
Start spawns the device simulator background tasks and its agent API server, also in the background
func (*DeviceSimulator) Stop ¶
func (ds *DeviceSimulator) Stop(mode simapi.StopMode)
Stop stops the device simulation agent and stops any background simulation tasks
func (*DeviceSimulator) Tables ¶
func (ds *DeviceSimulator) Tables() *entries.Tables
Tables returns the device tables store
func (*DeviceSimulator) UpdateConfig ¶ added in v0.1.20
func (ds *DeviceSimulator) UpdateConfig()
UpdateConfig should be called after the configuration tree has been updated to save the configuration and to reflect it back to the controller's Config structure for easy access.
func (*DeviceSimulator) UpdateIOStats ¶ added in v0.1.13
func (ds *DeviceSimulator) UpdateIOStats(byteCount int, input bool)
UpdateIOStats updates the device I/O stats
type HostSimulator ¶
HostSimulator simulates a single host
func NewHostSimulator ¶
func NewHostSimulator(host *simapi.Host, simulation *Simulation) *HostSimulator
NewHostSimulator initializes a new device simulator
func (*HostSimulator) EmitARPRequests ¶ added in v0.1.1
func (hs *HostSimulator) EmitARPRequests(nic *simapi.NetworkInterface, dstIPs []string) error
EmitARPRequests triggers the specified host NIC to send ARP requests for a set of IP addresses
func (*HostSimulator) GetNetworkInterfaceByMac ¶ added in v0.1.1
func (hs *HostSimulator) GetNetworkInterfaceByMac(mac string) *simapi.NetworkInterface
GetNetworkInterfaceByMac returns the network interface associated with the specified MAC address on this host
func (*HostSimulator) GetRandomNetworkInterface ¶
func (hs *HostSimulator) GetRandomNetworkInterface() *simapi.NetworkInterface
GetRandomNetworkInterface returns randomly chosen network interface for the host
func (*HostSimulator) SendARPRequest ¶
func (hs *HostSimulator) SendARPRequest(another *simapi.NetworkInterface)
SendARPRequest simulates emission of an ARP request as a packet-in on all the hosts' interfaces
func (*HostSimulator) SendARPResponse ¶
func (hs *HostSimulator) SendARPResponse(another *simapi.Host)
SendARPResponse simulates emission of an ARP response as a packet-in on all the hosts' interfaces
func (*HostSimulator) Start ¶
func (hs *HostSimulator) Start()
Start starts background host simulation activities, e.g. emitting ARP and DHCP packets
func (*HostSimulator) Stop ¶
func (hs *HostSimulator) Stop()
Stop stops any background host simulation activities
type IOStats ¶ added in v0.1.13
type IOStats struct { InBytes uint32 InMessages uint32 OutBytes uint32 OutMessages uint32 SinceTime time.Time }
IOStats represents cumulative I/O stats
type LinkSimulator ¶
LinkSimulator simulates a single link
func NewLinkSimulator ¶
func NewLinkSimulator(link *simapi.Link) *LinkSimulator
NewLinkSimulator initializes a new device simulator
type Simulation ¶
type Simulation struct { Collector *StatsCollector // contains filtered or unexported fields }
Simulation tracks all entities and activities related to device, host and link simulation
func NewSimulation ¶
func NewSimulation() *Simulation
NewSimulation creates a new core simulation entity
func (*Simulation) AddDeviceSimulator ¶
func (s *Simulation) AddDeviceSimulator(dev *simapi.Device, agent DeviceAgent) (*DeviceSimulator, error)
AddDeviceSimulator creates a new devices simulator for the specified device
func (*Simulation) AddHostSimulator ¶
func (s *Simulation) AddHostSimulator(host *simapi.Host) (*HostSimulator, error)
AddHostSimulator creates a new host simulator for the specified host
func (*Simulation) AddLinkSimulator ¶
func (s *Simulation) AddLinkSimulator(link *simapi.Link) (*LinkSimulator, error)
AddLinkSimulator creates a new link simulator for the specified link
func (*Simulation) EmitARPs ¶ added in v0.1.1
EmitARPs triggers the specified host NIC to send ARP requests for a set of IP addresses
func (*Simulation) GetDeviceSimulator ¶
func (s *Simulation) GetDeviceSimulator(id simapi.DeviceID) (*DeviceSimulator, error)
GetDeviceSimulator returns the simulator for the specified device ID
func (*Simulation) GetDeviceSimulatorForPort ¶
func (s *Simulation) GetDeviceSimulatorForPort(id simapi.PortID) (*DeviceSimulator, error)
GetDeviceSimulatorForPort returns the simulator for the specified device port ID
func (*Simulation) GetDeviceSimulators ¶
func (s *Simulation) GetDeviceSimulators() []*DeviceSimulator
GetDeviceSimulators returns a list of all device simulators
func (*Simulation) GetHostSimulator ¶
func (s *Simulation) GetHostSimulator(id simapi.HostID) (*HostSimulator, error)
GetHostSimulator returns the simulator for the specified host ID
func (*Simulation) GetHostSimulators ¶
func (s *Simulation) GetHostSimulators() []*HostSimulator
GetHostSimulators returns a list of all host simulators
func (*Simulation) GetLinkFromPort ¶
func (s *Simulation) GetLinkFromPort(portID simapi.PortID) *simapi.Link
GetLinkFromPort returns the link that originates from the specified device port; nil if none
func (*Simulation) GetLinkSimulator ¶
func (s *Simulation) GetLinkSimulator(id simapi.LinkID) (*LinkSimulator, error)
GetLinkSimulator returns the simulator for the specified link ID
func (*Simulation) GetLinkSimulators ¶
func (s *Simulation) GetLinkSimulators() []*LinkSimulator
GetLinkSimulators returns a list of all link simulators
func (*Simulation) GetRandomHostSimulator ¶
func (s *Simulation) GetRandomHostSimulator(except *HostSimulator) *HostSimulator
GetRandomHostSimulator returns a random host simulator; except the specified one, if not nil
func (*Simulation) RemoveDeviceSimulator ¶
func (s *Simulation) RemoveDeviceSimulator(id simapi.DeviceID) error
RemoveDeviceSimulator removes the simulator for the specified device ID and stops all its related activities
func (*Simulation) RemoveHostSimulator ¶
func (s *Simulation) RemoveHostSimulator(id simapi.HostID) error
RemoveHostSimulator removes the simulator for the specified host ID and stops all its related activities
func (*Simulation) RemoveLinkSimulator ¶
func (s *Simulation) RemoveLinkSimulator(id simapi.LinkID) error
RemoveLinkSimulator removes the simulator for the specified link ID and stops all its related activities
type StatsCollector ¶ added in v0.1.14
type StatsCollector struct {
// contains filtered or unexported fields
}
StatsCollector drives collection of I/O statistics as a time-series of rates and counters
func (*StatsCollector) GetIOStats ¶ added in v0.1.14
func (c *StatsCollector) GetIOStats() []*misc.IOStats
GetIOStats returns the list of I/O stats.
func (*StatsCollector) Start ¶ added in v0.1.14
func (c *StatsCollector) Start()
Start starts the I/O stats collector in the background
type StreamResponder ¶
type StreamResponder interface { ConnectionTracker // LatchMastershipArbitration record the mastership arbitration role and election ID if the arbitration update is not nil LatchMastershipArbitration(arbitration *p4api.MasterArbitrationUpdate) *p4api.MasterArbitrationUpdate // SendMastershipArbitration sends a mastership arbitration message to the controller with OK code if // the controller has the master election ID or with the given fail code otherwise SendMastershipArbitration(role *p4api.Role, masterElectionID *p4api.Uint128, failCode code.Code) // Send queues up the specified response to asynchronously sends on the backing stream Send(response *p4api.StreamMessageResponse) // IsMaster returns true if the responder is the current master, i.e. has the master election ID, for the given role. IsMaster(role *p4api.Role, masterElectionID *p4api.Uint128) bool // GetRoleConfig returns the stratum role configuration received during role arbitration GetRoleConfig() *stratum.P4RoleConfig }
StreamResponder is an abstraction for sending StreamResponse messages to controllers
type SubscribeResponder ¶
type SubscribeResponder interface { ConnectionTracker // Send queues up the specified response to asynchronously sends on the backing stream Send(response *gnmi.SubscribeResponse) }
SubscribeResponder is an abstraction for sending SubscribeResponse messages to controllers
Directories ¶
Path | Synopsis |
---|---|
Package config contains the configuration tree
|
Package config contains the configuration tree |
Package entries contains implementation of various P4 entitites such as tables, groups, meters, etc.
|
Package entries contains implementation of various P4 entitites such as tables, groups, meters, etc. |