chapar

package
v0.0.0-...-4a740ba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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

func CheckFrame(frame []byte) (err protocol.Error)

CheckFrame checks frame for any bad situation! Always check frame before use any other frame methods otherwise panic may occur!

func GetHopCount

func GetHopCount(frame []byte) byte

GetHopCount returns the number of intermediate network devices indicate in frame.

func GetNextHeader

func GetNextHeader(frame []byte) byte

GetNextHeader returns next header ID of the frame.

func GetNextHop

func GetNextHop(frame []byte) byte

GetNextHop returns next hop number.

func GetNextPortNum

func GetNextPortNum(frame []byte) byte

GetNextPortNum returns next port number set in the frame.

func GetPath

func GetPath(frame []byte) []byte

GetPath gets frame path in all hops.

func GetPayload

func GetPayload(frame []byte) []byte

GetPayload returns payload.

func GetPortNum

func GetPortNum(frame []byte, hopNum byte) byte

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

func GetReversePath(frame []byte) []byte

GetReversePath gets frame path in all hops just in reverse.

func IncrementNextHop

func IncrementNextHop(frame []byte, receivedPortNumber byte)

IncrementNextHop sets received port number and increment NextHop number in frame!

func IsBroadcastFrame

func IsBroadcastFrame(frame []byte) bool

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

func ReversePath(path []byte) (ReversePath []byte)

ReversePath returns a copy of given path in reverse.

func SetHopCount

func SetHopCount(frame []byte, hopCount byte)

SetHopCount writes given hop number to the frame.

func SetNextHeader

func SetNextHeader(frame []byte, linkHeaderID byte)

SetNextHeader sets next header id in the frame.

func SetPath

func SetPath(frame []byte, path []byte)

SetPath sets given path in given the frame.

func SetPortNum

func SetPortNum(frame []byte, hopNum byte, portNum byte)

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

type MakeTopologyRes struct {
	EndUserSwitch uint
	HopNumber     uint8
}

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) Decode

func (p *Path) Decode(reader io.Reader) (err protocol.Error)

Marshal return the path in the given frame.

func (*Path) Encode

func (p *Path) Encode(writer io.Writer) (err error)

Marshal return the path in the given frame.

func (*Path) Get

func (p *Path) Get() []byte

func (*Path) GetAsString

func (p *Path) GetAsString() string

func (*Path) GetReverse

func (p *Path) GetReverse() (reverse Path)

GetReverse return path in all hops just in reverse.

func (*Path) Init

func (p *Path) Init(frame []byte)

Init sets path from the given frame

func (*Path) Len

func (p *Path) Len() int

func (*Path) LenAsByte

func (p *Path) LenAsByte() byte

func (*Path) Marshal

func (p *Path) Marshal() (path []byte)

Marshal return the path in the given frame.

func (*Path) MarshalTo

func (p *Path) MarshalTo(frame []byte)

MarshalTo sets the path in the given frame.

func (*Path) MediaType

func (p *Path) MediaType() protocol.MediaType

func (*Path) Set

func (p *Path) Set(path []byte)

func (*Path) Unmarshal

func (p *Path) Unmarshal(path []byte) (err protocol.Error)

Unmarshal sets path from the given path

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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL