github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/protocol/networking-osi_2-data_link.go (about)

     1  /* For license and copyright information please see the LEGAL file in the code repository */
     2  
     3  package protocol
     4  
     5  /*
     6  **********************************************************************************
     7  Link - (OSI Layer 2: Data Link)
     8  
     9  It can use to network hardware devices in a computers or connect two or more computers.
    10  **********************************************************************************
    11  */
    12  
    13  type NetworkLink_NextHeaderID byte
    14  
    15  // https://github.com/GeniusesGroup/RFCs/blob/master/Chapar.md#next-header-standard-supported-protocols
    16  const (
    17  	NetworkLink_Unset NetworkLink_NextHeaderID = iota
    18  	NetworkLink_SRPC
    19  	NetworkLink_GP
    20  	NetworkLink_IPv6
    21  	NetworkLink_NTP
    22  
    23  	NetworkLink_Experimental1 NetworkLink_NextHeaderID = 251 // Use for non supported protocols like IPv4, ...
    24  	NetworkLink_Experimental2 NetworkLink_NextHeaderID = 252
    25  	NetworkLink_Experimental3 NetworkLink_NextHeaderID = 253
    26  	NetworkLink_Experimental4 NetworkLink_NextHeaderID = 254
    27  	NetworkLink_Experimental5 NetworkLink_NextHeaderID = 255
    28  )
    29  
    30  // NetworkLink_Multiplexer indicate a link frame multiplexer object methods must implemented by any os.
    31  type NetworkLink_Multiplexer interface {
    32  	// Send usually use to send a broadcast frame
    33  	Send(frame []byte) (err Error)
    34  	Receive(conn NetworkPhysical_Connection, frame []byte)
    35  
    36  	RegisterNetworkMux(transMux NetworkNetwork_Multiplexer)
    37  	UnRegisterNetworkMux(transMux NetworkNetwork_Multiplexer)
    38  
    39  	Shutdown()
    40  }
    41  
    42  // NetworkLink_Connection or Device2DeviceConnection
    43  type NetworkLink_Connection interface {
    44  	MTU() int
    45  
    46  	NewFrame(nexHeaderID NetworkLink_NextHeaderID, payloadLen int) (frame []byte, payload []byte, err Error)
    47  
    48  	// Send transmitting in non blocking mode and just queue frames for congestion situations.
    49  	// Return error not related to frame situation, just about any hardware error.
    50  	// A situation might be occur that the port available when a frame queued but when the time to send is come, the port broken and sender don't know about this.
    51  	// Due to speed matters in link layer, and it is very rare situation, it is better to ignore suddenly port unavailability.
    52  	// After return, caller can't reuse payload array anymore.
    53  	Send(frame []byte) (err Error)
    54  }