Documentation ¶
Index ¶
- Constants
- Variables
- func CheckFrame(frame []byte) (err protocol.Error)
- func GetHopCount(frame []byte) byte
- func GetNextHeader(frame []byte) byte
- func GetNextHop(frame []byte) byte
- func GetNextPortNum(frame []byte) byte
- func GetPath(frame []byte) []byte
- func GetPayload(frame []byte) []byte
- func GetPortNum(frame []byte, hopNum byte) byte
- func GetReversePath(frame []byte) []byte
- func IncrementNextHop(frame []byte, receivedPortNumber byte)
- func IsBroadcastFrame(frame []byte) bool
- func MakeNewFrame(nexHeaderID protocol.NetworkLinkNextHeaderID, path []byte, payload []byte) (frame []byte)
- func ReversePath(path []byte) (ReversePath []byte)
- func SetHopCount(frame []byte, hopCount byte)
- func SetNextHeader(frame []byte, linkHeaderID byte)
- func SetPath(frame []byte, path []byte)
- func SetPortNum(frame []byte, hopNum byte, portNum byte)
- type Connection
- type MakeTopologyReq
- type MakeTopologyRes
- type Multiplexer
- func (mux *Multiplexer) Init(pConnection protocol.NetworkPhysicalConnection)
- func (mux *Multiplexer) Receive(frame []byte)
- func (mux *Multiplexer) RegisterTransportHandler(tm protocol.NetworkTransportOSMultiplexer)
- func (mux *Multiplexer) Send(frame []byte) (err protocol.Error)
- func (mux *Multiplexer) SendBroadcast(nexHeaderID protocol.NetworkLinkNextHeaderID, payload protocol.Codec) (err protocol.Error)
- func (mux *Multiplexer) Shutdown()
- func (mux *Multiplexer) UnRegisterTransportHandler(tm protocol.NetworkTransportOSMultiplexer)
- type Path
- func (p *Path) CompressType() protocol.CompressType
- func (p *Path) Decode(reader io.Reader) (err protocol.Error)
- func (p *Path) Encode(writer io.Writer) (err error)
- func (p *Path) Get() []byte
- func (p *Path) GetAsString() string
- func (p *Path) GetReverse() (reverse Path)
- func (p *Path) Init(frame []byte)
- func (p *Path) Len() int
- func (p *Path) LenAsByte() byte
- func (p *Path) Marshal() (path []byte)
- func (p *Path) MarshalTo(frame []byte)
- func (p *Path) MediaType() protocol.MediaType
- func (p *Path) Set(path []byte)
- func (p *Path) Unmarshal(path []byte) (err protocol.Error)
- type UpperHandlerNonExist
- func (h *UpperHandlerNonExist) HeaderID() (id byte)
- func (h *UpperHandlerNonExist) Receive(conn protocol.NetworkLinkConnection, packet []byte)
- func (h *UpperHandlerNonExist) RegisterAppMultiplexer(appMux NetworkTransportAppMultiplexer)
- func (h *UpperHandlerNonExist) Shutdown()
- func (h *UpperHandlerNonExist) UnRegisterAppMultiplexer(appMux NetworkTransportAppMultiplexer)
Constants ¶
const ( // MinFrameLen is minimum Chapar frame length // 4 Byte Chapar header + 8 Byte min payload MinFrameLen = 12 // MaxFrameLen is maximum Chapar frame length MaxFrameLen = 8192 )
Variables ¶
var ( ErrShortFrameLength = er.New("urn:giti:chapar.protocol:error:short-frame-length").SetDetail(protocol.LanguageEnglish, errorEnglishDomain, "Short Frame Length", "Chapar frame is too short(<12) than standard", "", ""). SetDetail(protocol.LanguagePersian, errorPersianDomain, "اندازه کوتاه فریم", "ابعاد و اندازه فریم چاپار بررسی شده کمتر از 12 بایت می باشد که مجاز نمی باشد", "", "").Save() ErrLongFrameLength = er.New("urn:giti:chapar.protocol:error:long-frame-length").SetDetail(protocol.LanguageEnglish, errorEnglishDomain, "Long Frame Length", "Chapar frame is too long(>8192) than standard", "", ""). SetDetail(protocol.LanguagePersian, errorPersianDomain, "اندازه بلند فریم", "ابعاد و اندازه فریم چاپار بررسی شده بیشتر از 8192 بایت می باشد که مجاز نمی باشد", "", "").Save() ErrMTU = er.New("urn:giti:chapar.protocol:error:maximum-transmission-unit").SetDetail(protocol.LanguageEnglish, errorEnglishDomain, "Maximum Transmission Unit - MTU", "Chapar frame isn't legal due to MTU is not respected by payload!", "", ""). SetDetail(protocol.LanguagePersian, errorPersianDomain, "حداکثر طول قابل ارسال", "اندازه فریم چاپار بررسی شده بدلیل عدم رعایت طول در بار مفید فریم مجاز نمی باشد", "", "").Save() ErrPortNotExist = er.New("urn:giti:chapar.protocol:error:port-not-exist").SetDetail(protocol.LanguageEnglish, errorEnglishDomain, "Port Not Exist", "Chapar frame can't be handle due to frame want to switch to a port that not exist in network", "", ""). SetDetail(protocol.LanguagePersian, errorPersianDomain, "پورت وجود ندارد", "فریم چاپار قابلیت مسیریابی ندارد و دلیل هم درخواست به مسیری که وجود ندارد می باشد", "", "").Save() ErrPathAlreadyUse = er.New("urn:giti:chapar.protocol:error:path-already-use").SetDetail(protocol.LanguageEnglish, errorEnglishDomain, "Path Already Use", "Path already use as main chapar connection path", "", ""). SetDetail(protocol.LanguagePersian, errorPersianDomain, "مسیر در حال استفاده می باشد", "مسیری که برای مسیر اصلی ارتباط انتخاب شده است با مسیر فعلی یکسان می باشد", "", "").Save() ErrPathAlreadyExist = er.New("urn:giti:chapar.protocol:error:path-already-exist").SetDetail(protocol.LanguageEnglish, errorEnglishDomain, "Path Already Exist", "Path already exist in chapar connection alternative paths", "", ""). SetDetail(protocol.LanguagePersian, errorPersianDomain, "مسیر موجود می باشد", "مسیری که برای اضافه کردن به مسیرهای جایگزین به ارتباط انتخاب شده است قبلا اضافه شده است", "", "").Save() )
Declare Errors Details
Functions ¶
func CheckFrame ¶
CheckFrame checks frame for any bad situation! Always check frame before use any other frame methods otherwise panic may occur!
func GetHopCount ¶
GetHopCount returns the number of intermediate network devices indicate in frame.
func GetNextHeader ¶
GetNextHeader returns next header ID of the frame.
func GetNextPortNum ¶
GetNextPortNum returns next port number set in the frame.
func GetPortNum ¶
GetPortNum returns port number of given hop number. First hopNum is hopNum==1 not hopNum==0. Don't read hopNum==0 due to it is use for broadcast frame.
func GetReversePath ¶
GetReversePath gets frame path in all hops just in reverse.
func IncrementNextHop ¶
IncrementNextHop sets received port number and increment NextHop number in frame!
func IsBroadcastFrame ¶
IsBroadcastFrame checks frame is broadcast frame or not! spec: https://github.com/GeniusesGroup/RFCs/blob/master/Chapar.md#frame-types
func MakeNewFrame ¶
func MakeNewFrame(nexHeaderID protocol.NetworkLinkNextHeaderID, path []byte, payload []byte) (frame []byte)
MakeNewFrame makes new unicast||broadcast frame!
func ReversePath ¶
ReversePath returns a copy of given path in reverse.
func SetHopCount ¶
SetHopCount writes given hop number to the frame.
func SetNextHeader ¶
SetNextHeader sets next header id in the frame.
func SetPortNum ¶
SetPortNum set given port number in given hop number! First hopNum is hopNum==1 not hopNum==0. Don't set hopNum==0 due to it is use for broadcast frame.
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection ---Read locale description in chaparConnectionStructure---
func (*Connection) MTU ¶
func (c *Connection) MTU() int
MTU return max payload size that this connection can carry on active path!
func (*Connection) Send ¶
func (c *Connection) Send(nexHeaderID protocol.NetworkLinkNextHeaderID, payload protocol.Codec) (err protocol.Error)
Send use for
func (*Connection) SendAsync ¶
func (c *Connection) SendAsync(nexHeaderID protocol.NetworkLinkNextHeaderID, payload protocol.Codec) (err protocol.Error)
SendAsync use to send the frame async!
type MakeTopologyReq ¶
type MakeTopologyReq struct { EndUser uint GateWayPort uint // Last hop free port UserHopEfficiency uint8 // How many physical link to upper hop Efficiency uint8 // How many physical link to upper hop }
MakeTopologyReq is request structure of MakeTopology()
type MakeTopologyRes ¶
MakeTopologyRes is response structure of MakeTopology()
func MakeTopology ¶
func MakeTopology(req *MakeTopologyReq) (res *MakeTopologyRes)
MakeTopology calculate some data to implement Chapar network easily.
type Multiplexer ¶
type Multiplexer struct {
// contains filtered or unexported fields
}
Multiplexer implement protocol.LinkMultiplexer interface Hardware implementation has one difference from Software(this) implementation: Software: Receive method call Receive method of desire port Hardware: Receive method will call Send method of desire port
func (*Multiplexer) Init ¶
func (mux *Multiplexer) Init(pConnection protocol.NetworkPhysicalConnection)
Init initializes new Multiplexer object otherwise panic will occur on un-registered port or handler call!
func (*Multiplexer) Receive ¶
func (mux *Multiplexer) Receive(frame []byte)
Receive handles income frame to ports!
func (*Multiplexer) RegisterTransportHandler ¶
func (mux *Multiplexer) RegisterTransportHandler(tm protocol.NetworkTransportOSMultiplexer)
RegisterTransportHandler registers new port on given ports pool!
func (*Multiplexer) Send ¶
func (mux *Multiplexer) Send(frame []byte) (err protocol.Error)
Send send the payload to all ports async!
func (*Multiplexer) SendBroadcast ¶
func (mux *Multiplexer) SendBroadcast(nexHeaderID protocol.NetworkLinkNextHeaderID, payload protocol.Codec) (err protocol.Error)
SendBroadcast send the payload to all ports async!
func (*Multiplexer) Shutdown ¶
func (mux *Multiplexer) Shutdown()
Shutdown ready the connection pools to shutdown!!
func (*Multiplexer) UnRegisterTransportHandler ¶
func (mux *Multiplexer) UnRegisterTransportHandler(tm protocol.NetworkTransportOSMultiplexer)
UnRegisterTransportHandler delete the port by given port number on given ports pool!
type Path ¶
type Path struct {
// contains filtered or unexported fields
}
Path indicate Chapar switch route plan!
func (*Path) CompressType ¶
func (p *Path) CompressType() protocol.CompressType
func (*Path) GetAsString ¶
func (*Path) GetReverse ¶
GetReverse return path in all hops just in reverse.
type UpperHandlerNonExist ¶
type UpperHandlerNonExist struct {
// contains filtered or unexported fields
}
UpperHandlerNonExist use for default and empty switch port due to non of ports can be nil!
func (*UpperHandlerNonExist) HeaderID ¶
func (h *UpperHandlerNonExist) HeaderID() (id byte)
RegisterMultiplexer register given multiplexer to the port for further usage!
func (*UpperHandlerNonExist) Receive ¶
func (h *UpperHandlerNonExist) Receive(conn protocol.NetworkLinkConnection, packet []byte)
Receive get packet to route it to its path!
func (*UpperHandlerNonExist) RegisterAppMultiplexer ¶
func (h *UpperHandlerNonExist) RegisterAppMultiplexer(appMux NetworkTransportAppMultiplexer)
func (*UpperHandlerNonExist) Shutdown ¶
func (h *UpperHandlerNonExist) Shutdown()
func (*UpperHandlerNonExist) UnRegisterAppMultiplexer ¶
func (h *UpperHandlerNonExist) UnRegisterAppMultiplexer(appMux NetworkTransportAppMultiplexer)