Documentation ¶
Overview ¶
Package nom contains the Network Object Model: an abstraction for computer networks. In essence it is a graph of networking nodes similar to what is proposed in ONIX.
NOM models a network as a graph of nodes. Each node has a set of ports with outgoing links that are connected to other ports.
- +===============================================
- | Author: Elahe Jalalpour (el.jalalpour@gmail.com)
- |
- | Creation Date: 24-11-2015
- |
- | File Name: host.go
- +===============================================
Index ¶
- Constants
- Variables
- func ParseLinkUID(id UID) (NodeID, PortID, LinkID)
- func ParsePortUID(id UID) (NodeID, PortID)
- func UIDSplit(id UID) []string
- type Action
- type ActionDrop
- type ActionFlood
- type ActionForward
- type ActionPopVLAN
- type ActionPushVLAN
- type ActionSendToController
- type ActionWriteFields
- type AddFlowEntry
- type AddPath
- type AddTrigger
- type Bandwidth
- type ChangeDriverRole
- type DelFlowEntry
- type DelPath
- type DelTrigger
- type Driver
- type DriverRole
- type DriverRoleUpdate
- type Drivers
- type EthAddrField
- type EthDst
- type EthSrc
- type EthType
- type Field
- type FlowEntry
- type FlowEntryAdded
- type FlowEntryDeleted
- type FlowStats
- type FlowStatsQuery
- type FlowStatsQueryResult
- type Host
- type HostConnected
- type HostDisconnected
- type HostID
- type HostJoined
- type HostLeft
- type IPProto
- type IPv4Addr
- type IPv4Dst
- type IPv4Src
- type IPv6Addr
- type IPv6Dst
- type IPv6Src
- type InPort
- type Link
- type LinkAdded
- type LinkDeleted
- type LinkID
- type LinkState
- type MACAddr
- type MaskedIPv4Addr
- type MaskedIPv6Addr
- type MaskedMACAddr
- type Match
- func (m *Match) AddField(f Field)
- func (m Match) Clone() Match
- func (m Match) Equals(thatm Match) bool
- func (m Match) EthDst() (EthDst, bool)
- func (m Match) EthSrc() (EthSrc, bool)
- func (m Match) EthType() (EthType, bool)
- func (m Match) IPv4Dst() (IPv4Dst, bool)
- func (m Match) IPv4Src() (IPv4Src, bool)
- func (m Match) IPv6Dst() (IPv6Dst, bool)
- func (m Match) IPv6Src() (IPv6Src, bool)
- func (m Match) InPort() (InPort, bool)
- func (m Match) String() string
- func (m Match) Subsumes(thatm Match) bool
- func (m Match) TransportPortDst() (TransportPortDst, bool)
- func (m Match) TransportPortSrc() (TransportPortSrc, bool)
- func (m Match) VLANID() (VLANID, bool)
- func (m Match) VLANPCP() (VLANPCP, bool)
- type Network
- type NetworkID
- type Node
- type NodeCapability
- type NodeConnected
- type NodeDisconnected
- type NodeID
- type NodeJoined
- type NodeLeft
- type NodeQuery
- type NodeQueryResult
- type Object
- type Packet
- type PacketBufferID
- type PacketIn
- type PacketOut
- type Path
- type PathAdded
- type PathDelReason
- type PathDeleted
- type Pathlet
- type Ping
- type Pong
- type Port
- type PortConfig
- type PortFeature
- type PortID
- type PortQuery
- type PortQueryResult
- type PortState
- type PortStatusChanged
- type PortUpdated
- type Ports
- type TransportPortDst
- type TransportPortSrc
- type Trigger
- type Triggered
- type UID
- type VLANID
- type VLANPCP
Constants ¶
const ( EthTypeIPv4 EthType = 0x0800 EthTypeIPv6 = 0x86DD EthTypeARP = 0x0806 EthTypeLLDP = 0x88CC )
Valid values for EthType.
const ( LinkStateUnknown LinkState = iota LinkStateUp = iota LinkStateDown = iota )
Valid values for LinkState.
const ( PortStateUnknown PortState = iota // Port's state is unknown. PortStateDown = iota // Port is not connected to any link. PortStateUp = iota // Port is up and forwarding packets. PortStateBlocked = iota // Port is blocked. )
Valid values for PortState.
const ( PortConfigDown PortConfig = 1 << iota // Down. PortConfigDropPackets = 1 << iota // Drop incoming packets. PortConfigNoForward = 1 << iota // Do not forward packets. PortConfigNoFlood = 1 << iota // Do not include in flood. PortConfigNoPacketIn = 1 << iota // Do not send packet ins. PortConfigDisableStp = 1 << iota // Disable STP. PortConfigDropStp = 1 << iota // Drop STP packets. )
Valid values for PortConfig.
const ( PortFeature10MBHD PortFeature = 1 << iota // 10MB half-duplex. PortFeature10MBFD = 1 << iota // 10MB full-duplex. PortFeature100MBHD = 1 << iota // 100MB half-duplex. PortFeature100MBFD = 1 << iota // 100MB half-duplex. PortFeature1GBHD = 1 << iota // 1GB half-duplex. PortFeature1GBFD = 1 << iota // 1GB half-duplex. PortFeature10GBHD = 1 << iota // 10GB half-duplex. PortFeature10GBFD = 1 << iota // 10GB half-duplex. PortFeatureCopper = 1 << iota // Copper. PortFeatureFiber = 1 << iota // Fiber. PortFeatureAutoneg = 1 << iota // Auto negotiation. PortPause = 1 << iota // Pause. PortPauseAsym = 1 << iota // Asymmetric pause. )
Valid values for PortFeature
const (
Nil = ""
)
const UIDSeparator = "$$"
UIDSeparator is the token added in between the parts of a UID.
Variables ¶
var ( MaskNoneMAC MACAddr = [6]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} BroadcastMAC MACAddr = [6]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} CDPMulticastMAC MACAddr = [6]byte{0x01, 0x00, 0x0C, 0xCC, 0xCC, 0xCC} CiscoSTPMulticastMAC MACAddr = [6]byte{0x01, 0x00, 0x0C, 0xCC, 0xCC, 0xCD} IEEE802MulticastPrefix MACAddr = [6]byte{0x01, 0x80, 0xC2, 0x00, 0x00, 0x00} IPv4MulticastPrefix MACAddr = [6]byte{0x01, 0x00, 0x5E, 0x00, 0x00, 0x00} IPv6MulticastPrefix MACAddr = [6]byte{0x33, 0x33, 0x00, 0x00, 0x00, 0x00} LLDPMulticastMACs []MACAddr = []MACAddr{ [6]byte{0x01, 0x80, 0xC2, 0x00, 0x00, 0x0E}, [6]byte{0x01, 0x80, 0xC2, 0x00, 0x00, 0x0C}, [6]byte{0x01, 0x80, 0xC2, 0x00, 0x00, 0x00}, } MaskNoneIPV4 IPv4Addr = [4]byte{0xFF, 0xFF, 0xFF, 0xFF} MaskNoneIPV6 IPv6Addr = [16]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} )
Functions ¶
func ParseLinkUID ¶
ParseLinkUID parses a link UID into the respetive node, port, and link ids.
func ParsePortUID ¶
ParsePortUID parses a UID of a port and returns the respective node and port IDs.
Types ¶
type ActionDrop ¶
type ActionDrop struct { }
func (ActionDrop) Equals ¶
func (a ActionDrop) Equals(thata Action) bool
func (ActionDrop) String ¶
func (a ActionDrop) String() string
type ActionFlood ¶
type ActionFlood struct {
InPort UID
}
func (ActionFlood) Equals ¶
func (a ActionFlood) Equals(thata Action) bool
func (ActionFlood) String ¶
func (a ActionFlood) String() string
type ActionForward ¶
type ActionForward struct {
Ports []UID
}
func (ActionForward) Equals ¶
func (a ActionForward) Equals(thata Action) bool
func (ActionForward) String ¶
func (a ActionForward) String() string
type ActionPopVLAN ¶
type ActionPopVLAN struct{}
func (ActionPopVLAN) Equals ¶
func (a ActionPopVLAN) Equals(thata Action) bool
type ActionPushVLAN ¶
type ActionPushVLAN struct {
ID VLANID
}
func (ActionPushVLAN) Equals ¶
func (a ActionPushVLAN) Equals(thata Action) bool
type ActionSendToController ¶
type ActionSendToController struct {
MaxLen uint16
}
func (ActionSendToController) Equals ¶
func (a ActionSendToController) Equals(thata Action) bool
type ActionWriteFields ¶
type ActionWriteFields struct {
Fields []Field
}
func (ActionWriteFields) Equals ¶
func (a ActionWriteFields) Equals(thata Action) bool
type AddFlowEntry ¶
type AddFlowEntry struct { Subscriber bh.AppCellKey Flow FlowEntry }
AddFlowEntry is a message emitted to install a flow entry on a node.
type AddPath ¶
type AddPath struct { Subscriber bh.AppCellKey Path Path }
AddPath is emitted to install a path in the network.
type ChangeDriverRole ¶
type ChangeDriverRole struct { Node UID // Tho node ID. Role DriverRole // The requested new role. Generation uint64 // The generation of role request. }
ChangeDriverRole is emitted to instruct a driver to change its role for a node.
type DelFlowEntry ¶
DelFlowEntry is emitted to remove the flow entries with the given match. If Exact is false, it removes all flow entries that are subsumed by the given match.
type DelPath ¶
type DelPath struct {
Path Path
}
DelPath is emitted to delete a path from the network.
type DelTrigger ¶
type DelTrigger Trigger
DelTrigger is a message emitted to remove a trigger for a specific subscriber.
type Driver ¶
type Driver struct { BeeID uint64 Role DriverRole }
Driver represents the Bee that communicates with the actual networking element and adapts the southbound protocol for using in NOM.
func (*Driver) JSONDecode ¶
JSONDecode decodes the driver from a byte slice using JSON.
func (*Driver) JSONEncode ¶
JSONEncode encodes the driver into a byte slice using JSON.
type DriverRole ¶
type DriverRole uint8
DriverRole is the role of a driver for a node. The values can be either default, slave or master. Only one driver can be the master, but we can have multiple slaves and multiple defaults.
const ( DriverRoleDefault DriverRole = iota DriverRoleSlave DriverRoleMaster )
Valid values for DriverRole.
type DriverRoleUpdate ¶
DriverRoleUpdate is a message emitted when a driver's role is changed or an update (no necessarily a change) is recevied for a node.
type Drivers ¶
type Drivers []Driver
func (*Drivers) JSONDecode ¶
JSONDecode decodes the drivers from a byte slice using JSON.
func (*Drivers) JSONEncode ¶
JSONEncode encodes the drivers into a byte slice using JSON.
type EthAddrField ¶
EthAddrField is a common type for EthDst and EthSrc.
type EthDst ¶
type EthDst MaskedMACAddr
EthDst is the field for Ethernet destination address.
func (EthDst) HasSameType ¶
type EthSrc ¶
type EthSrc MaskedMACAddr
EthSrc is the field for Ethernet source address.
func (EthSrc) HasSameType ¶
type EthType ¶
type EthType uint16
EthType represents the field for an Ethernet type.
func (EthType) HasSameType ¶
type FlowEntry ¶
type FlowEntry struct { ID string // ID is defined by the subscriber, not globally unique. Node UID Match Match Actions []Action Priority uint16 IdleTimeout time.Duration HardTimeout time.Duration }
FlowEntry represents a match-action rule for a specific node.
type FlowEntryAdded ¶
type FlowEntryAdded struct {
Flow FlowEntry
}
FlowEntryAdded is emitted (broadcasted and also sent to the subscriber of the flow) when a flow is added. If the flow already existed, the message is emitted to the subscriber.
type FlowEntryDeleted ¶
type FlowEntryDeleted struct {
Flow FlowEntry
}
FlowEntryDeleted is emitted (broadcasted and also sent to the subscriber of the flow) when a flow is deleted.
type FlowStatsQuery ¶
FlowStatsQuery queries the flows that would match the query. If Exact is false, it removes all flow entries that are subsumed by the given match.
type FlowStatsQueryResult ¶
FlowStatsQueryResult is the result for a FlowStatQuery
type Host ¶
Host represnts a end point element, such as your pc.
func (*Host) JSONDecode ¶
JSONDecode decodes the host from a byte array using JSON.
func (*Host) JSONEncode ¶
JSONEncode encodes the host into a byte array using JSON.
type HostConnected ¶
type HostConnected Host
HostConnected is a message emitted when a host connects to network, we use this event in order to add host into our cells.
type HostDisconnected ¶
type HostDisconnected Host
HostConnected is a message emitted when a host disconnects from network, we use this event in order to remove host from our cells.
type HostID ¶
type HostID string
HostID is the ID of a host. This must be unique among all hosts in the network.
func ParseHostUID ¶
ParseHostUID parses a UID of a host and returns the respective host IDs.
type HostJoined ¶
type HostJoined Host
HostJoined is a message emitted when a host connects to network and we added it into our cells.
type IPv4Addr ¶
type IPv4Addr [4]byte
IPv4Addr represents an IP version 4 address in big endian byte order. For example, 127.0.0.1 is represented as IPv4Addr{127, 0, 0, 1}.
func (IPv4Addr) AsCIDRMask ¶
AsCIDRMask returns the CIDR prefix number based on this address. For example, it returns 24 for 255.255.255.0.
type IPv6Addr ¶
type IPv6Addr [16]byte
IPv6Addr represents an IP version 6 address in big-endian byte order.
func (IPv6Addr) AsCIDRMask ¶
AsCIDRMask returns the CIDR prefix number based on this address.
type Link ¶
type Link struct { ID LinkID // Link's ID. From UID // From is the link's port. To UID // To stores the port(s) connected to From using this link. State LinkState // The link's state. }
Link represents an outgoing link from a port.
func (*Link) JSONDecode ¶
JSONDecode decodes the node from a byte array using JSON.
func (*Link) JSONEncode ¶
JSONEncode encodes the node into a byte array using JSON.
type LinkID ¶
type LinkID string
LinkID is a link's ID which is unique among the outgoing links of a port.
type MACAddr ¶
type MACAddr [6]byte
MACAddr represents a MAC address.
func (MACAddr) IsBroadcast ¶
IsBroadcast returns whether the MAC address is a broadcast address.
func (MACAddr) IsLLDP ¶
IsLLDP returns whether the mac address is a multicast address used for LLDP.
func (MACAddr) IsMulticast ¶
IsMulticast returns whether the MAC address is a multicast address.
type MaskedIPv4Addr ¶
MaskedIPv4Addr represents a masked IP address (ie, an IPv4 prefix)
func CIDRToMaskedIPv4 ¶
func CIDRToMaskedIPv4(addr uint32, mask uint) MaskedIPv4Addr
CIDRToMaskedIPv4 converts a CIDR-style IP address into a NOM masked IP address. For example, if addr is 0x7F000001 and mask is 24, this function returns {IPv4Addr{127, 0, 0, 1}, IPv4Addr{255, 255, 255, 0}}.
func (MaskedIPv4Addr) Match ¶
func (mi MaskedIPv4Addr) Match(ip IPv4Addr) bool
Match returns whether the masked IP address matches ip.
func (MaskedIPv4Addr) String ¶
func (mi MaskedIPv4Addr) String() string
func (MaskedIPv4Addr) Subsumes ¶
func (mi MaskedIPv4Addr) Subsumes(thatmi MaskedIPv4Addr) bool
type MaskedIPv6Addr ¶
MaskedIPv6Addr represents a masked IPv6 address.
func (MaskedIPv6Addr) Match ¶
func (mi MaskedIPv6Addr) Match(ip IPv6Addr) bool
Match returns whether the masked IP address matches ip.
func (MaskedIPv6Addr) String ¶
func (mi MaskedIPv6Addr) String() string
func (MaskedIPv6Addr) Subsumes ¶
func (mi MaskedIPv6Addr) Subsumes(thatmi MaskedIPv6Addr) bool
type MaskedMACAddr ¶
type MaskedMACAddr struct { Addr MACAddr // The MAC address. Mask MACAddr // The mask of the MAC address. }
MaskedMACAddr is a MAC address that is wildcarded with a mask.
func (MaskedMACAddr) Match ¶
func (mm MaskedMACAddr) Match(mac MACAddr) bool
Match returns whether the masked mac address matches mac.
func (MaskedMACAddr) Subsumes ¶
func (mm MaskedMACAddr) Subsumes(thatmm MaskedMACAddr) bool
Subsumes returns whether this mask address includes all the addresses matched by thatmm.
type Match ¶
type Match struct {
Fields []Field
}
Match is a collection of fields that will match packets.
func (Match) TransportPortDst ¶
func (m Match) TransportPortDst() (TransportPortDst, bool)
func (Match) TransportPortSrc ¶
func (m Match) TransportPortSrc() (TransportPortSrc, bool)
type Network ¶
type Network struct { ID NetworkID // The id of the network. Desc string // A human-readable description of the network. }
Network represents a virtual or physical network in NOM.
func (*Network) JSONDecode ¶
JSONDecode decodes the network from a byte slice using JSON.
func (*Network) JSONEncode ¶
JSONEncode encodes the network into a byte slice using JSON.
type NetworkID ¶
type NetworkID string
NetworkID is the ID of the network.
func ParseNetworkUID ¶
ParseNetworkUID parses a network UID into the network ID. Note that for network these IDs of the same.
type Node ¶
type Node struct { ID NodeID Net UID Capabilities []NodeCapability MACAddr MACAddr }
Node represents a forwarding element, such as switches and routers.
func (Node) HasCapability ¶
func (n Node) HasCapability(c NodeCapability) bool
func (*Node) JSONDecode ¶
JSONDecode decodes the node from a byte array using JSON.
func (*Node) JSONEncode ¶
JSONEncode encodes the node into a byte array using JSON.
type NodeCapability ¶
type NodeCapability uint32
NodeCapability is a capability of a NOM node.
const (
CapDriverRole NodeCapability = 1 << iota // Node can set the driver's role.
)
Valid values for NodeCapability.
type NodeConnected ¶
NodeConnected is a message emitted when a node connects to a driver.
type NodeDisconnected ¶
NodeDisconnected is a message emitted when a node disconnects from its driver.
type NodeID ¶
type NodeID string
NodeID is the ID of a node. This must be unique among all nodes in the network.
func ParseNodeUID ¶
ParseNodeUID parses a UID of a node and returns the respective node IDs.
type NodeJoined ¶
type NodeJoined Node
NodeJoined is a message emitted when a node joins the network through the controller. It is always emitted after processing NodeConnected in the controller.
type NodeLeft ¶
type NodeLeft Node
NodeLeft is a message emitted when a node disconnects from its driver. It is always emitted after processing NodeDisconnected in the controller.
type NodeQueryResult ¶
NodeQueryResult is the result for NodeQuery.
type Object ¶
type Object interface { // JSONDecode decodes the object from a byte array using the JSON encoding. JSONDecode(b []byte) error // JSONEncode encodes the object into a byte array using the JSON encoding. JSONEncode() ([]byte, error) // UID returns a unique ID of this object. This ID is unique in the network // among all other objects. UID() UID }
Object is the interface of all structs in the network object model.
type Packet ¶
type Packet []byte
Packet is simply the packet data.
type PacketBufferID ¶
type PacketBufferID uint32
PacketBufferID represents a packet buffered in the switch.
type PacketIn ¶
type PacketIn struct { Node UID InPort UID BufferID PacketBufferID Packet Packet }
PacketIn messages are emitted when a packet is forwarded to the controller.
type PacketOut ¶
type PacketOut struct { Node UID InPort UID BufferID PacketBufferID Packet Packet Actions []Action }
PacketOut messages are emitted to send a packet out of a port.
type Path ¶
type Path struct { ID string // ID needs to be unique only to the subscriber. Pathlets []Pathlet // Pathlets in the path. Priority uint16 // Priority of this path. }
Path is a logical sequence of pathlets, where pathlet[i+1] will match the output of pathlet[i]. If pathlet[i+1] matches on an incoming port p1, pathlet[i] should have a forward action that forwards to a port 2 directly connected to p1. Clearly, this rule does not apply to the first and the last pathlets in the path.
type PathAdded ¶
type PathAdded struct {
Path Path
}
PathAdded is emitted to the subscriber when the path is successfully added.
type PathDelReason ¶
type PathDelReason int
PathDelReason is the reason that a path is deleted.
const ( // PathDelExplicit means that the path is explicitly deleted using a DelPath. PathDelExplicit PathDelReason = iota // PathDelInvalid means that the path has contradicting pathlets. PathDelInvalid // PathDelInfeasible means that the path is valid but cannot be formed due to // the current state of the network. PathDelInfeasible )
type PathDeleted ¶
type PathDeleted struct { Path Path Reason PathDelReason }
PathDeleted is emitted to the subscriber when the path is deleted (because it cannot be installed in the network, or because it is explicitly removed).
type Pathlet ¶
type Pathlet struct { Match Match // Pathlet's match. Exclude []InPort // Exclude packets from these ports in the pathlet. Actions []Action // Action that are applied. }
Pathlet represents a logical connection pathlet in a path, where incoming packets matching Match are processing using Actions.
type Ping ¶
type Ping struct{}
Ping represents a ping message sent to a driver. It is used to health-check the driver.
type Port ¶
type Port struct { ID PortID // ID is unique among the ports of this node. Name string // Human-readable name of the port. MACAddr MACAddr // Hardware address of the port. Node UID // The node. Link UID // The outgoing link. State PortState // Is the state of the port. Config PortConfig // Is the configuration of the port. Feature PortFeature // Features of this port. }
Port is either a physical or a virtual port of a node.
func (*Port) JSONDecode ¶
JSONDecode decodes the port from a byte array using JSON.
func (*Port) JSONEncode ¶
JSONEncode encodes the port into a byte array using JSON.
type PortID ¶
type PortID string
PortID is the ID of a port and is unique among the ports of a node.
type PortQueryResult ¶
PortQueryResult is the result for a PortQuery.
type PortStatusChanged ¶
PortStatusChanged is emitted when a driver receives a port status
type PortUpdated ¶
type PortUpdated Port
PortUpdated is a high-level event emitted when a port is added, removed, or its state/configuration is changed.
type Ports ¶
type Ports []Port
Ports is a slice of ports with useful auxilaries.
func (*Ports) DelPort ¶
DelPort deletes port from ports. If there is no such port, it returns false.
type TransportPortDst ¶
type TransportPortDst uint16
func (TransportPortDst) Equals ¶
func (p TransportPortDst) Equals(f Field) bool
func (TransportPortDst) HasSameType ¶
func (p TransportPortDst) HasSameType(f Field) bool
func (TransportPortDst) String ¶
func (p TransportPortDst) String() string
func (TransportPortDst) Subsumes ¶
func (p TransportPortDst) Subsumes(f Field) bool
type TransportPortSrc ¶
type TransportPortSrc uint16
func (TransportPortSrc) Equals ¶
func (p TransportPortSrc) Equals(f Field) bool
func (TransportPortSrc) HasSameType ¶
func (p TransportPortSrc) HasSameType(f Field) bool
func (TransportPortSrc) String ¶
func (p TransportPortSrc) String() string
func (TransportPortSrc) Subsumes ¶
func (p TransportPortSrc) Subsumes(f Field) bool
type Trigger ¶
type Trigger struct { Subscriber bh.AppCellKey // Triggered messages sent to the Subscriber. Node UID // The node. Match Match // The mathing criteria. Exact bool // Whether Match should exactly match the flow. Duration time.Duration // Minimum live duration to trigger. Bandwidth Bandwidth // Minimum bandwidth consumption to trigger. }
Trigger represents a flow trigger. When a trigger is installed on a node, the node will be queried continuiously. Whenever any matching flow goes beyond the given bandwidth consumption or lives beyond the given duration, a Triggered message will be emitted.
type UID ¶
type UID string
UID is a unique ID of a NOM object. Unlike UUID/GUID, this ID contains redundant information about the object. For example a port's UID contains its network and node ID along with an ID for the port.
func NodeFromPortUID ¶
NodeFromPortUID returns the node UID from the port's UID.
type VLANID ¶
type VLANID uint16
VLANID represents the field for the VLAN ID.
func (VLANID) HasSameType ¶
type VLANPCP ¶
type VLANPCP uint8
VLANPCP represents the field for the VLAN PCP.