You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2024/10/04 10:55:18 UTC
(plc4x) 01/02: feat(plc4go/bacnetip): add debug printing for netservice
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 19d07f9c1bca4a32818b7a5ac5050ee586ad0d69
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Oct 2 11:16:25 2024 +0200
feat(plc4go/bacnetip): add debug printing for netservice
---
.../internal/bacnetip/bacgopes/apdu/apdu_APDU.go | 5 +-
.../bacgopes/debugging/debugging_DebugContents.go | 1 +
.../bacnetip/bacgopes/netservice/netservice.go | 7 +-
.../netservice/netservice_NetworkAdapter.go | 9 +
.../netservice_NetworkServiceAccessPoint.go | 143 ++++++++++++++++
.../netservice/netservice_NetworkServiceElement.go | 189 +++++++++++++++++----
.../netservice/netservice_RouterInfoCache.go | 56 ++++++
7 files changed, 376 insertions(+), 34 deletions(-)
diff --git a/plc4go/internal/bacnetip/bacgopes/apdu/apdu_APDU.go b/plc4go/internal/bacnetip/bacgopes/apdu/apdu_APDU.go
index 3b7f8a7f66..6e3d2628ae 100644
--- a/plc4go/internal/bacnetip/bacgopes/apdu/apdu_APDU.go
+++ b/plc4go/internal/bacnetip/bacgopes/apdu/apdu_APDU.go
@@ -21,6 +21,7 @@ package apdu
import (
"context"
+ "fmt"
"github.com/pkg/errors"
@@ -63,7 +64,7 @@ func NewAPDU(args Args, kwArgs KWArgs, options ...Option) (APDU, error) {
func (a *__APDU) Encode(pdu Arg) error {
if _debug != nil {
- _debug("encode %s", pdu)
+ _debug("encode %s", pdu.(fmt.Stringer).String())
}
if err := a._APCI.Encode(pdu); err != nil {
return errors.Wrap(err, "error encoding APCI")
@@ -77,7 +78,7 @@ func (a *__APDU) Encode(pdu Arg) error {
func (a *__APDU) Decode(pdu Arg) error {
if _debug != nil {
- _debug("decode %s", pdu)
+ _debug("decode %s", pdu.(fmt.Stringer).String())
}
var rootMessage spi.Message
switch pdu := pdu.(type) { // Save a root message as long as we have enough data
diff --git a/plc4go/internal/bacnetip/bacgopes/debugging/debugging_DebugContents.go b/plc4go/internal/bacnetip/bacgopes/debugging/debugging_DebugContents.go
index 17ac56fb60..a626d0b125 100644
--- a/plc4go/internal/bacnetip/bacgopes/debugging/debugging_DebugContents.go
+++ b/plc4go/internal/bacnetip/bacgopes/debugging/debugging_DebugContents.go
@@ -91,6 +91,7 @@ func (d *DebugContents) LeafNameOrFallback() string {
if leafNameSupplier, ok := debuggable.(interface{ GetLeafName() string }); ok {
return leafNameSupplier.GetLeafName()
}
+ return QualifiedTypeName(debuggable)
}
return StructName()
}
diff --git a/plc4go/internal/bacnetip/bacgopes/netservice/netservice.go b/plc4go/internal/bacnetip/bacgopes/netservice/netservice.go
index 1e9adeb274..1407568587 100644
--- a/plc4go/internal/bacnetip/bacgopes/netservice/netservice.go
+++ b/plc4go/internal/bacnetip/bacgopes/netservice/netservice.go
@@ -19,9 +19,12 @@
package netservice
-import . "github.com/apache/plc4x/plc4go/internal/bacnetip/bacgopes/comp"
+import (
+ . "github.com/apache/plc4x/plc4go/internal/bacnetip/bacgopes/comp"
+ . "github.com/apache/plc4x/plc4go/internal/bacnetip/bacgopes/debugging"
+)
-// TODO: add debug printing
+var _debug = CreateDebugPrinter()
// used for net keys like snet and dnet (tri state)
type netKey = NillableKey[uint16]
diff --git a/plc4go/internal/bacnetip/bacgopes/netservice/netservice_NetworkAdapter.go b/plc4go/internal/bacnetip/bacgopes/netservice/netservice_NetworkAdapter.go
index fba7038cfe..2c5c31ebea 100644
--- a/plc4go/internal/bacnetip/bacgopes/netservice/netservice_NetworkAdapter.go
+++ b/plc4go/internal/bacnetip/bacgopes/netservice/netservice_NetworkAdapter.go
@@ -61,6 +61,9 @@ func NewNetworkAdapter(localLog zerolog.Logger, sap *NetworkServiceAccessPoint,
if err != nil {
return nil, errors.Wrap(err, "error creating client")
}
+ if _debug != nil {
+ _debug("__init__ %s %r %r cid=%r", sap, net, addr, n.GetClientID())
+ }
// record if this was 0=learned, 1=configured, None=unknown
if net != nil {
var state = 1
@@ -101,6 +104,9 @@ func (n *NetworkAdapter) Confirmation(args Args, kwArgs KWArgs) error {
Msg("confirmation")
pdu := GA[PDU](args, 0)
+ if _debug != nil {
+ _debug("confirmation %r (net=%r)", pdu, n.adapterNet)
+ }
npdu, err := NewNPDU(NoArgs, NKW(KWCPCIUserData, pdu.GetPDUUserData()))
if err != nil {
@@ -118,6 +124,9 @@ func (n *NetworkAdapter) ProcessNPDU(npdu NPDU) error {
Stringer("npdu", npdu).
Interface("adapterNet", n.adapterNet).
Msg("ProcessNPDU")
+ if _debug != nil {
+ _debug("process_npdu %r (net=%r)", npdu, n.adapterNet)
+ }
pdu := NewPDU(NoArgs, NKW(KWCPCIUserData, npdu.GetPDUUserData()))
if err := npdu.Encode(pdu); err != nil {
diff --git a/plc4go/internal/bacnetip/bacgopes/netservice/netservice_NetworkServiceAccessPoint.go b/plc4go/internal/bacnetip/bacgopes/netservice/netservice_NetworkServiceAccessPoint.go
index fe7a53de53..d7b341d2e6 100644
--- a/plc4go/internal/bacnetip/bacgopes/netservice/netservice_NetworkServiceAccessPoint.go
+++ b/plc4go/internal/bacnetip/bacgopes/netservice/netservice_NetworkServiceAccessPoint.go
@@ -66,6 +66,9 @@ func NewNetworkServiceAccessPoint(localLog zerolog.Logger, options ...Option) (*
if err != nil {
return nil, errors.Wrap(err, "error creating server")
}
+ if _debug != nil {
+ _debug("__init__ sap=%r sid=%r", n.GetServiceElement(), n.GetServiceID())
+ }
// map of directly connected networks
n.adapters = make(map[netKey]*NetworkAdapter)
@@ -122,6 +125,9 @@ func (n *NetworkServiceAccessPoint) Bind(server Server, net *uint16, address *Ad
Interface("net", net).
Stringer("address", address).
Msg("bind")
+ if _debug != nil {
+ _debug("bind %r net=%r address=%r", server, net, address)
+ }
// make sure this hasn't already been called with this network
if _, ok := n.adapters[nk(net)]; ok {
@@ -137,10 +143,16 @@ func (n *NetworkServiceAccessPoint) Bind(server Server, net *uint16, address *Ad
Interface("net", net).
Stringer("adapter", adapter).
Msg("adapter")
+ if _debug != nil {
+ _debug(" - adapter: %r, %r", net, adapter)
+ }
// if the address was given, make it the "local" one
if address != nil {
n.log.Debug().Msg("setting local adapter")
+ if _debug != nil {
+ _debug(" - setting local adapter")
+ }
n.localAdapter = adapter
}
@@ -148,11 +160,17 @@ func (n *NetworkServiceAccessPoint) Bind(server Server, net *uint16, address *Ad
// be overridden by a subsequent call if the address is specified
if n.localAdapter == nil {
n.log.Debug().Msg("default local adapter")
+ if _debug != nil {
+ _debug(" - default local adapter")
+ }
n.localAdapter = adapter
}
if n.localAdapter.adapterAddr == nil {
n.log.Debug().Msg("no local address")
+ if _debug != nil {
+ _debug(" - no local address")
+ }
}
return Bind(n.log, adapter, server)
@@ -165,6 +183,9 @@ func (n *NetworkServiceAccessPoint) UpdateRouterReference(snet *uint16, address
Stringer("address", address).
Interface("dnets", dnets).
Msg("UpdateRouterReference")
+ if _debug != nil {
+ _debug("update_router_references %r %r %r", snet, address, dnets)
+ }
// see if we have an adapter for the snet
_, ok := n.adapters[nk(snet)]
@@ -183,6 +204,9 @@ func (n *NetworkServiceAccessPoint) DeleteRouterReference(snet *uint16, address
Stringer("address", address).
Interface("dnets", dnets).
Msg("NetworkServiceAccessPoint")
+ if _debug != nil {
+ _debug("delete_router_references %r %r %r", snet, address, dnets)
+ }
// see if we have an adapter for the snet
_, ok := n.adapters[nk(snet)]
@@ -198,6 +222,9 @@ func (n *NetworkServiceAccessPoint) Indication(args Args, kwArgs KWArgs) error {
n.log.Debug().Stringer("Args", args).Stringer("KWArgs", kwArgs).Msg("Indication")
pdu := GA[PDU](args, 0)
+ if _debug != nil {
+ _debug("indication %r", pdu)
+ }
// make sure our configuration is OK
if len(n.adapters) == 0 {
@@ -207,6 +234,9 @@ func (n *NetworkServiceAccessPoint) Indication(args Args, kwArgs KWArgs) error {
// get the local adapter
localAdapter := n.localAdapter
n.log.Debug().Stringer("localAdapter", localAdapter).Msg("localAdapter")
+ if _debug != nil {
+ _debug(" - local_adapter: %r", localAdapter)
+ }
// build a generic APDU
apdu, err := NewAPDU(NoArgs, NKW(KWCPCIUserData, pdu.GetPDUUserData())) // Note: upstream uses _APDU which looks like the _APDU class but is an alias to APDU
@@ -217,6 +247,9 @@ func (n *NetworkServiceAccessPoint) Indication(args Args, kwArgs KWArgs) error {
return errors.Wrap(err, "error encoding APDU")
}
n.log.Debug().Stringer("_APDU", apdu).Msg("apdu")
+ if _debug != nil {
+ _debug(" - apdu: %r", apdu)
+ }
// build an NPDU specific to where it is going
npdu, err := NewNPDU(NoArgs, NKW(KWCPCIUserData, pdu.GetPDUUserData()))
@@ -227,6 +260,9 @@ func (n *NetworkServiceAccessPoint) Indication(args Args, kwArgs KWArgs) error {
return errors.Wrap(err, "error encoding NPDU")
}
n.log.Debug().Stringer("npdu", npdu).Msg("npdu")
+ if _debug != nil {
+ _debug(" - npdu: %r", npdu)
+ }
// the hop count always starts out big
hopCount := uint8(0xff)
@@ -240,9 +276,15 @@ func (n *NetworkServiceAccessPoint) Indication(args Args, kwArgs KWArgs) error {
if npdu.GetPDUDestination().AddrRoute.AddrType != LOCAL_STATION_ADDRESS {
panic("Route must be of type local station")
}
+ if _debug != nil {
+ _debug(" - routed: %r", npdu.GetPDUDestination().AddrRoute)
+ }
switch pdu.GetPDUDestination().AddrType {
case REMOTE_STATION_ADDRESS, REMOTE_BROADCAST_ADDRESS, GLOBAL_BROADCAST_ADDRESS:
+ if _debug != nil {
+ _debug(" - continue DADR: %r", apdu.GetPDUDestination())
+ }
npdu.SetNpduDADR(apdu.GetPDUDestination())
}
@@ -283,18 +325,27 @@ func (n *NetworkServiceAccessPoint) Indication(args Args, kwArgs KWArgs) error {
dnet := npdu.GetPDUDestination().AddrNet
n.log.Debug().Interface("dnet", dnet).Msg("using dnet")
+ if _debug != nil {
+ _debug(" - dnet: %r", dnet)
+ }
// if the network matches the local adapter it's local
if dnet == localAdapter.adapterNet {
switch npdu.GetPDUDestination().AddrType {
case REMOTE_STATION_ADDRESS:
n.log.Debug().Msg("mapping remote station to local station")
+ if _debug != nil {
+ _debug(" - mapping remote station to local station")
+ }
localStation, err := NewLocalStation(npdu.GetPDUDestination().AddrAddress, nil)
if err != nil {
return errors.Wrap(err, "error building local station")
}
pdu.SetPDUDestination(localStation)
case REMOTE_BROADCAST_ADDRESS:
+ if _debug != nil {
+ _debug(" - mapping remote broadcast to local broadcast")
+ }
pdu.SetPDUDestination(NewLocalBroadcast(nil))
default:
return errors.New("Addressing problem")
@@ -309,6 +360,9 @@ func (n *NetworkServiceAccessPoint) Indication(args Args, kwArgs KWArgs) error {
// we might already be waiting for a path for this network
if pendingNet, ok := n.pendingNets[nk(dnet)]; ok {
n.log.Debug().Msg("already waiting for a path")
+ if _debug != nil {
+ _debug(" - already waiting for path")
+ }
n.pendingNets[nk(dnet)] = append(pendingNet, npdu)
return nil
}
@@ -327,10 +381,16 @@ func (n *NetworkServiceAccessPoint) Indication(args Args, kwArgs KWArgs) error {
// if there is info, we have a path
if routerInfo != nil {
n.log.Debug().Stringer("routerInfo", routerInfo).Msg("routerInfo found")
+ if _debug != nil {
+ _debug(" - router_info found: %r", routerInfo)
+ }
// check the path status
dnetStatus := routerInfo.dnets[nk(dnet)]
n.log.Debug().Interface("dnetStatus", dnetStatus).Msg("dnetStatus")
+ if _debug != nil {
+ _debug(" - dnet_status: %r", dnetStatus)
+ }
// fix the destination
npdu.SetPDUDestination(routerInfo.address)
@@ -339,6 +399,9 @@ func (n *NetworkServiceAccessPoint) Indication(args Args, kwArgs KWArgs) error {
return snetAdapter.ProcessNPDU(npdu)
} else {
n.log.Debug().Msg("no known path to network")
+ if _debug != nil {
+ _debug(" - no known path to network")
+ }
// add it to the list of packets waiting for the network
netList, _ := n.pendingNets[nk(dnet)]
@@ -368,6 +431,9 @@ func (n *NetworkServiceAccessPoint) ProcessNPDU(adapter *NetworkAdapter, npdu NP
Stringer("adapter", adapter).
Stringer("npdu", npdu).
Msg("ProcessNPDU")
+ if _debug != nil {
+ _debug("process_npdu %r %r", adapter, npdu)
+ }
// make sure our configuration is OK
if len(n.adapters) == 0 {
@@ -381,6 +447,9 @@ func (n *NetworkServiceAccessPoint) ProcessNPDU(adapter *NetworkAdapter, npdu NP
// check for source routing
if npdu.GetNpduSADR() != nil && npdu.GetNpduSADR().AddrType != NULL_ADDRESS {
n.log.Debug().Msg("check source path")
+ if _debug != nil {
+ _debug(" - check source path")
+ }
// see if this is attempting to spoof a directly connected network
snet := npdu.GetSourceNetworkAddress()
@@ -398,11 +467,17 @@ func (n *NetworkServiceAccessPoint) ProcessNPDU(adapter *NetworkAdapter, npdu NP
// check for destination routing
case npdu.GetNpduDADR() == nil || npdu.GetNpduDADR().AddrType == NULL_ADDRESS:
n.log.Debug().Msg("no DADR")
+ if _debug != nil {
+ _debug(" - no DADR")
+ }
processLocally = adapter == n.localAdapter || npdu.GetControl().GetMessageTypeFieldPresent()
forwardMessage = false
case npdu.GetNpduDADR().AddrType == REMOTE_BROADCAST_ADDRESS:
n.log.Debug().Msg("DADR is remote broadcast")
+ if _debug != nil {
+ _debug(" - DADR is remote broadcast")
+ }
if *npdu.GetNpduDADR().AddrNet == *adapter.adapterNet {
n.log.Warn().Msg("path error (2)")
@@ -413,6 +488,9 @@ func (n *NetworkServiceAccessPoint) ProcessNPDU(adapter *NetworkAdapter, npdu NP
forwardMessage = true
case npdu.GetNpduDADR().AddrType == REMOTE_STATION_ADDRESS:
n.log.Debug().Msg("DADR is remote station")
+ if _debug != nil {
+ _debug(" - DADR is remote station")
+ }
if *npdu.GetNpduDADR().AddrNet == *adapter.adapterNet {
n.log.Warn().Msg("path error (3)")
@@ -423,6 +501,9 @@ func (n *NetworkServiceAccessPoint) ProcessNPDU(adapter *NetworkAdapter, npdu NP
forwardMessage = !processLocally
case npdu.GetNpduDADR().AddrType == GLOBAL_BROADCAST_ADDRESS:
n.log.Debug().Msg("DADR is global broadcast")
+ if _debug != nil {
+ _debug(" - DADR is global broadcast")
+ }
processLocally = true
forwardMessage = true
@@ -433,10 +514,17 @@ func (n *NetworkServiceAccessPoint) ProcessNPDU(adapter *NetworkAdapter, npdu NP
n.log.Debug().Bool("processLocally", processLocally).Msg("processLocally")
n.log.Debug().Bool("forwardMessage", forwardMessage).Msg("forwardMessage")
+ if _debug != nil {
+ _debug(" - processLocally: %r", processLocally)
+ _debug(" - forwardMessage: %r", forwardMessage)
+ }
// application or network layer message
if !npdu.GetControl().GetMessageTypeFieldPresent() {
n.log.Debug().Msg("application layer message")
+ if _debug != nil {
+ _debug(" - application layer message")
+ }
if processLocally && n.HasServerPeer() {
n.log.Trace().Msg("processing APDU locally")
@@ -445,6 +533,9 @@ func (n *NetworkServiceAccessPoint) ProcessNPDU(adapter *NetworkAdapter, npdu NP
if err != nil {
return errors.Wrap(err, "error creating APDU")
}
+ if _debug != nil {
+ _debug(" - apdu: %r", apdu)
+ }
if err := apdu.Decode(DeepCopy[NPDU](npdu)); err != nil {
return errors.Wrap(err, "error decoding APDU")
}
@@ -482,6 +573,9 @@ func (n *NetworkServiceAccessPoint) ProcessNPDU(adapter *NetworkAdapter, npdu NP
apdu.SetPDUSource(npdu.GetNpduSADR())
if Settings.RouteAware {
n.log.Debug().Msg("adding route")
+ if _debug != nil {
+ _debug(" - adding route")
+ }
apdu.GetPDUSource().AddrRoute = npdu.GetPDUSource()
}
} else {
@@ -498,6 +592,10 @@ func (n *NetworkServiceAccessPoint) ProcessNPDU(adapter *NetworkAdapter, npdu NP
n.log.Debug().Stringer("pduSource", apdu.GetPDUSource()).Msg("apdu.pduSource")
n.log.Debug().Stringer("pduDestination", apdu.GetPDUDestination()).Msg("apdu.pduDestination")
+ if _debug != nil {
+ _debug(" - apdu.pduSource: %r", apdu.GetPDUSource())
+ _debug(" - apdu.pduDestination: %r", apdu.GetPDUDestination())
+ }
// pass upstream to the application layer
if err := n.Response(NA(apdu), NoKWArgs()); err != nil {
@@ -506,14 +604,23 @@ func (n *NetworkServiceAccessPoint) ProcessNPDU(adapter *NetworkAdapter, npdu NP
}
} else {
n.log.Debug().Msg("network layer message")
+ if _debug != nil {
+ _debug(" - network layer message")
+ }
if processLocally {
np, ok := NPDUTypes[npdu.GetNlm().GetMessageType()]
if !ok {
n.log.Debug().Uint8("messageType", npdu.GetNlm().GetMessageType()).Msg("unknown npdu type")
+ if _debug != nil {
+ _debug(" - unknown npdu type: %r", npdu.GetNPDUNetMessage())
+ }
return nil
}
n.log.Debug().Msg("processing NPDU locally")
+ if _debug != nil {
+ _debug(" - processing NPDU locally")
+ }
// do a deeper decode of the NPDU
xpdu := np()
@@ -531,18 +638,27 @@ func (n *NetworkServiceAccessPoint) ProcessNPDU(adapter *NetworkAdapter, npdu NP
// might not need to forward this to other devices
if !forwardMessage {
n.log.Debug().Msg("no forwarding")
+ if _debug != nil {
+ _debug(" - no forwarding")
+ }
return nil
}
// make sure we're really a router
if len(n.adapters) == 1 {
n.log.Debug().Msg("not a router")
+ if _debug != nil {
+ _debug(" - not a router")
+ }
return nil
}
// make sure it hasn't looped
if npdu.GetHopCount() != nil && *npdu.GetHopCount() == 0 {
n.log.Debug().Msg("no more hops")
+ if _debug != nil {
+ _debug(" - no more hops")
+ }
return nil
}
@@ -572,6 +688,9 @@ func (n *NetworkServiceAccessPoint) ProcessNPDU(adapter *NetworkAdapter, npdu NP
// If this is a broadcast it goes everywhere
if npdu.GetNpduDADR().AddrType == GLOBAL_BROADCAST_ADDRESS {
n.log.Debug().Msg("global broadcasting")
+ if _debug != nil {
+ _debug(" - global broadcasting")
+ }
newpdu.SetPDUDestination(NewLocalBroadcast(nil))
@@ -588,14 +707,23 @@ func (n *NetworkServiceAccessPoint) ProcessNPDU(adapter *NetworkAdapter, npdu NP
if npdu.GetNpduDADR().AddrType == REMOTE_BROADCAST_ADDRESS || npdu.GetNpduDADR().AddrType == REMOTE_STATION_ADDRESS {
dnet := npdu.GetNpduDADR().AddrNet
n.log.Debug().Msg("remote station/broadcast")
+ if _debug != nil {
+ _debug(" - remote station/broadcast")
+ }
// see if this a locally connected network
if xadapter, ok := n.adapters[nk(dnet)]; ok {
if xadapter == adapter {
n.log.Debug().Msg("path error (4)")
+ if _debug != nil {
+ _debug(" - path error (4)")
+ }
return nil
}
n.log.Debug().Stringer("adapter", adapter).Msg("found path via")
+ if _debug != nil {
+ _debug(" - found path via %r", xadapter)
+ }
// if this was a remote broadcast, it's now a local one
if npdu.GetNpduDADR().AddrType == REMOTE_BROADCAST_ADDRESS {
@@ -629,6 +757,9 @@ func (n *NetworkServiceAccessPoint) ProcessNPDU(adapter *NetworkAdapter, npdu NP
// found a path
if routerInfo != nil {
n.log.Debug().Stringer("routerInfo", routerInfo).Msg("found path via routerInfo")
+ if _debug != nil {
+ _debug(" - found path via %r", routerInfo)
+ }
// the destination is the address of the router
newpdu.SetPDUDestination(routerInfo.address)
@@ -641,6 +772,9 @@ func (n *NetworkServiceAccessPoint) ProcessNPDU(adapter *NetworkAdapter, npdu NP
}
n.log.Debug().Msg("No router info found")
+ if _debug != nil {
+ _debug(" - no router info found")
+ }
// try to find a path to the network
xnpdu := model.NewNLMWhoIsRouterToNetwork(dnet, 0)
@@ -666,6 +800,9 @@ func (n *NetworkServiceAccessPoint) ProcessNPDU(adapter *NetworkAdapter, npdu NP
Interface("destinationNetworkAddress", npdu.GetDestinationNetworkAddress()).
Interface("destinationAddress", npdu.GetDestinationAddress()).
Msg("bad DADR")
+ if _debug != nil {
+ _debug(" - bad DADR: %r", npdu.GetNpduDADR())
+ }
return nil
}
@@ -673,6 +810,9 @@ func (n *NetworkServiceAccessPoint) SapIndication(args Args, kwArgs KWArgs) erro
n.log.Debug().Stringer("Args", args).Stringer("KWArgs", kwArgs).Msg("SapIndication")
adapter := GA[*NetworkAdapter](args, 0)
npdu := GA[NPDU](args, 1)
+ if _debug != nil {
+ _debug("sap_indication %r %r", adapter, npdu)
+ }
// encode it as a generic NPDU
xpdu, err := NewNPDU(NoArgs, NKW(KWCPCIUserData, npdu.GetPDUUserData()))
@@ -692,6 +832,9 @@ func (n *NetworkServiceAccessPoint) SapConfirmation(args Args, kwArgs KWArgs) er
n.log.Debug().Stringer("Args", args).Stringer("KWArgs", kwArgs).Msg("SapConfirmation")
adapter := GA[*NetworkAdapter](args, 0)
npdu := GA[NPDU](args, 1)
+ if _debug != nil {
+ _debug("sap_confirmation %r %r", adapter, npdu)
+ }
// encode it as a generic NPDU
xpdu, err := NewNPDU(NoArgs, NKW(KWCPCIUserData, npdu.GetPDUUserData()))
diff --git a/plc4go/internal/bacnetip/bacgopes/netservice/netservice_NetworkServiceElement.go b/plc4go/internal/bacnetip/bacgopes/netservice/netservice_NetworkServiceElement.go
index 8d6d04eaae..3c02213e19 100644
--- a/plc4go/internal/bacnetip/bacgopes/netservice/netservice_NetworkServiceElement.go
+++ b/plc4go/internal/bacnetip/bacgopes/netservice/netservice_NetworkServiceElement.go
@@ -61,6 +61,9 @@ func NewNetworkServiceElement(localLog zerolog.Logger, options ...Option) (*Netw
if err != nil {
return nil, errors.Wrap(err, "error creating application service element")
}
+ if _debug != nil {
+ _debug("__init__ eid=%r", n.GetElementId())
+ }
// network number is timeout
n.networkNumberIsTask = time.Time{}
@@ -78,21 +81,36 @@ func WithNetworkServiceElementStartupDisabled(startupDisabled bool) GenericAppli
func (n *NetworkServiceElement) Startup(_ Args, _ KWArgs) error {
n.log.Debug().Msg("Startup")
+ if _debug != nil {
+ _debug("startup")
+ }
// reference the service access point
sap := n.GetElementService().(*NetworkServiceAccessPoint) // TODO: hard cast but seems like adapters appears first in network service access point (so hard binding)
n.log.Debug().Stringer("sap", sap).Msg("sap")
+ if _debug != nil {
+ _debug(" - sap: %r", sap)
+ }
// loop through all the adapters
for _, adapter := range sap.adapters {
n.log.Debug().Stringer("adapter", adapter).Msg("adapter")
+ if _debug != nil {
+ _debug(" - adapter: %r", adapter)
+ }
if adapter.adapterNet == nil {
n.log.Trace().Msg("skipping, unknown net")
+ if _debug != nil {
+ _debug(" - skipping, unknown net")
+ }
continue
}
if adapter.adapterAddr == nil {
n.log.Trace().Msg("skipping, unknown addr")
+ if _debug != nil {
+ _debug(" - skipping, unknown addr")
+ }
continue
}
@@ -112,6 +130,9 @@ func (n *NetworkServiceElement) Startup(_ Args, _ KWArgs) error {
// skip for an empty list, perhaps they are not yet learned
if len(netlist) == 0 {
n.log.Trace().Msg("skipping, no netlist")
+ if _debug != nil {
+ _debug(" - skipping, no netlist")
+ }
continue
}
@@ -131,6 +152,9 @@ func (n *NetworkServiceElement) Indication(args Args, kwArgs KWArgs) error {
adapter := GA[*NetworkAdapter](args, 0)
npdu := GA[NPDU](args, 1)
+ if _debug != nil {
+ _debug("indication %r %r", adapter, npdu)
+ }
switch message := npdu.GetRootMessage().(type) {
case model.NPDU:
@@ -140,25 +164,25 @@ func (n *NetworkServiceElement) Indication(args Args, kwArgs KWArgs) error {
case model.NLMIAmRouterToNetwork:
return n.IAmRouterToNetwork(adapter, npdu, nlm)
case model.NLMICouldBeRouterToNetwork:
- return n.ICouldBeRouterToNetwork(adapter, nlm)
+ return n.ICouldBeRouterToNetwork(adapter, npdu, nlm)
case model.NLMRejectMessageToNetwork:
- return n.RejectRouterToNetwork(adapter, nlm)
+ return n.RejectRouterToNetwork(adapter, npdu, nlm)
case model.NLMRouterBusyToNetwork:
- return n.RouterBusyToNetwork(adapter, nlm)
+ return n.RouterBusyToNetwork(adapter, npdu, nlm)
case model.NLMRouterAvailableToNetwork:
- return n.RouterAvailableToNetwork(adapter, nlm)
+ return n.RouterAvailableToNetwork(adapter, npdu, nlm)
case model.NLMInitializeRoutingTable:
- return n.InitalizeRoutingTable(adapter, nlm)
+ return n.InitalizeRoutingTable(adapter, npdu, nlm)
case model.NLMInitializeRoutingTableAck:
- return n.InitalizeRoutingTableAck(adapter, nlm)
+ return n.InitalizeRoutingTableAck(adapter, npdu, nlm)
case model.NLMEstablishConnectionToNetwork:
- return n.EstablishConnectionToNetwork(adapter, nlm)
+ return n.EstablishConnectionToNetwork(adapter, npdu, nlm)
case model.NLMDisconnectConnectionToNetwork:
- return n.DisconnectConnectionToNetwork(adapter, nlm)
+ return n.DisconnectConnectionToNetwork(adapter, npdu, nlm)
case model.NLMWhatIsNetworkNumber:
- return n.WhatIsNetworkNumber(adapter, nlm)
+ return n.WhatIsNetworkNumber(adapter, npdu, nlm)
case model.NLMNetworkNumberIs:
- return n.NetworkNumberIs(adapter, nlm)
+ return n.NetworkNumberIs(adapter, npdu, nlm)
default:
n.log.Debug().Stringer("nlm", nlm).Msg("Unhandled")
}
@@ -173,6 +197,9 @@ func (n *NetworkServiceElement) Confirmation(args Args, kwArgs KWArgs) error {
adapter := GA[*NetworkAdapter](args, 0)
npdu := GA[NPDU](args, 1)
+ if _debug != nil {
+ _debug("confirmation %r %r", adapter, npdu)
+ }
switch message := npdu.GetRootMessage().(type) {
case model.NPDU:
@@ -182,25 +209,25 @@ func (n *NetworkServiceElement) Confirmation(args Args, kwArgs KWArgs) error {
case model.NLMIAmRouterToNetwork:
return n.IAmRouterToNetwork(adapter, npdu, nlm)
case model.NLMICouldBeRouterToNetwork:
- return n.ICouldBeRouterToNetwork(adapter, nlm)
+ return n.ICouldBeRouterToNetwork(adapter, npdu, nlm)
case model.NLMRejectMessageToNetwork:
- return n.RejectRouterToNetwork(adapter, nlm)
+ return n.RejectRouterToNetwork(adapter, npdu, nlm)
case model.NLMRouterBusyToNetwork:
- return n.RouterBusyToNetwork(adapter, nlm)
+ return n.RouterBusyToNetwork(adapter, npdu, nlm)
case model.NLMRouterAvailableToNetwork:
- return n.RouterAvailableToNetwork(adapter, nlm)
+ return n.RouterAvailableToNetwork(adapter, npdu, nlm)
case model.NLMInitializeRoutingTable:
- return n.InitalizeRoutingTable(adapter, nlm)
+ return n.InitalizeRoutingTable(adapter, npdu, nlm)
case model.NLMInitializeRoutingTableAck:
- return n.InitalizeRoutingTableAck(adapter, nlm)
+ return n.InitalizeRoutingTableAck(adapter, npdu, nlm)
case model.NLMEstablishConnectionToNetwork:
- return n.EstablishConnectionToNetwork(adapter, nlm)
+ return n.EstablishConnectionToNetwork(adapter, npdu, nlm)
case model.NLMDisconnectConnectionToNetwork:
- return n.DisconnectConnectionToNetwork(adapter, nlm)
+ return n.DisconnectConnectionToNetwork(adapter, npdu, nlm)
case model.NLMWhatIsNetworkNumber:
- return n.WhatIsNetworkNumber(adapter, nlm)
+ return n.WhatIsNetworkNumber(adapter, npdu, nlm)
case model.NLMNetworkNumberIs:
- return n.NetworkNumberIs(adapter, nlm)
+ return n.NetworkNumberIs(adapter, npdu, nlm)
default:
n.log.Debug().Stringer("nlm", nlm).Msg("Unhandled")
}
@@ -215,10 +242,16 @@ func (n *NetworkServiceElement) iamRouterToNetwork(args Args, _ KWArgs) error {
destination, _ := GAO[*Address](args, 1, nil)
network, _ := GAO[[]*uint16](args, 2, nil)
n.log.Debug().Stringer("adapter", adapter).Stringer("destination", destination).Interface("network", network).Msg("IamRouterToNetwork")
+ if _debug != nil {
+ _debug("i_am_router_to_network %r %r %r", adapter, destination, network)
+ }
// reference the service access point
sap := n.GetElementService().(*NetworkServiceAccessPoint) // TODO: hard cast but seems like adapters appears first in network service access point (so hard binding)
n.log.Debug().Interface("sap", sap).Msg("SAP")
+ if _debug != nil {
+ _debug(" - sap: %r", sap)
+ }
// if we're not a router, trouble
if len(sap.adapters) == 1 {
@@ -277,6 +310,9 @@ func (n *NetworkServiceElement) iamRouterToNetwork(args Args, _ KWArgs) error {
}
}
n.log.Debug().Stringer("adapter", adapter).Stringer("destination", destination).Interface("network", network).Msg("adapter, destination, network")
+ if _debug != nil {
+ _debug(" - adapter, destination, network: %r, %r, %r", adapter, destination, network)
+ }
// process a single adapter or all of the adapters
var adapterList []*NetworkAdapter
@@ -315,6 +351,9 @@ func (n *NetworkServiceElement) iamRouterToNetwork(args Args, _ KWArgs) error {
}
iamrtn.SetPDUDestination(destination)
n.log.Debug().Stringer("adapter", adapter).Stringer("iamrtn", iamrtn).Msg("adapter, iamrtn")
+ if _debug != nil {
+ _debug(" - adapter, iamrtn: %r, %r", adapter, iamrtn)
+ }
// send it back
if err := n.Request(NA(adapter, iamrtn), NoKWArgs()); err != nil {
@@ -327,19 +366,31 @@ func (n *NetworkServiceElement) iamRouterToNetwork(args Args, _ KWArgs) error {
func (n *NetworkServiceElement) WhoIsRouterToNetwork(adapter *NetworkAdapter, npdu NPDU, nlm model.NLMWhoIsRouterToNetwork) error {
n.log.Debug().Stringer("adapter", adapter).Stringer("npdu", npdu).Stringer("nlm", nlm).Msg("WhoIsRouteToNetwork")
+ if _debug != nil {
+ _debug("WhoIsRouterToNetwork %r %r", adapter, npdu)
+ }
// reference the service access point
sap := n.GetElementService().(*NetworkServiceAccessPoint) // TODO: check hard cast here...
n.log.Debug().Stringer("sap", sap).Msg("sap")
+ if _debug != nil {
+ _debug(" - sap: %r", sap)
+ }
// if we're not a router, skip it
if len(sap.adapters) == 1 {
n.log.Trace().Msg("not a router")
+ if _debug != nil {
+ _debug(" - not a router")
+ }
return nil
}
if destinationNetworkAddress := nlm.GetDestinationNetworkAddress(); destinationNetworkAddress == nil {
// requesting all networks
n.log.Trace().Msg("requesting all network")
+ if _debug != nil {
+ _debug(" - requesting all networks")
+ }
// build a list of reachable networks
var netlist []uint16
@@ -357,6 +408,9 @@ func (n *NetworkServiceElement) WhoIsRouterToNetwork(adapter *NetworkAdapter, np
if len(netlist) > 0 {
n.log.Debug().Uints16("netlist", netlist).Msg("found these")
+ if _debug != nil {
+ _debug(" - found these: %r", netlist)
+ }
// build a response
iamrtn, err := NewIAmRouterToNetwork(NoArgs, NewKWArgs(KWCPCIUserData, npdu.GetPDUUserData()), WithIAmRouterToNetworkNetworkList(netlist...))
@@ -375,14 +429,23 @@ func (n *NetworkServiceElement) WhoIsRouterToNetwork(adapter *NetworkAdapter, np
wirtnNetwork := *destinationNetworkAddress
// requesting a specific network
n.log.Debug().Uint16("wirtnNetwork", wirtnNetwork).Msg("requesting specific network")
+ if _debug != nil {
+ _debug(" - requesting specific network: %r", wirtnNetwork)
+ }
dnet := wirtnNetwork
// check the directly connected networks
if otherAdapter, ok := sap.adapters[nk(&dnet)]; ok {
n.log.Trace().Msg("directly connected")
+ if _debug != nil {
+ _debug(" - directly connected")
+ }
if otherAdapter == adapter {
n.log.Trace().Msg("same network")
+ if _debug != nil {
+ _debug(" - same network")
+ }
return nil
}
@@ -412,9 +475,15 @@ func (n *NetworkServiceElement) WhoIsRouterToNetwork(adapter *NetworkAdapter, np
// found a path
if routerInfo != nil {
n.log.Debug().Stringer("routerInfo", routerInfo).Msg("router round")
+ if _debug != nil {
+ _debug(" - router found: %r", routerInfo)
+ }
if snetAdapter == adapter {
n.log.Trace().Msg("same network")
+ if _debug != nil {
+ _debug(" - same network")
+ }
return nil
}
@@ -429,6 +498,9 @@ func (n *NetworkServiceElement) WhoIsRouterToNetwork(adapter *NetworkAdapter, np
return n.Response(NA(adapter, iamrtn), NoKWArgs())
} else {
n.log.Trace().Msg("forwarding to other adapters")
+ if _debug != nil {
+ _debug(" - forwarding to other adapters")
+ }
whoisrtn, err := NewWhoIsRouterToNetwork(NoArgs, NewKWArgs(KWCPCIUserData, npdu.GetPDUUserData()), WithWhoIsRouterToNetworkNet(dnet))
if err != nil {
@@ -446,11 +518,17 @@ func (n *NetworkServiceElement) WhoIsRouterToNetwork(adapter *NetworkAdapter, np
}
whoisrtn.SetNpduSADR(station)
}
+ if _debug != nil {
+ _debug(" - whoisrtn: %r", whoisrtn)
+ }
// send it to all (other) adapters
for _, xadapter := range sap.adapters {
if xadapter != adapter {
n.log.Debug().Stringer("xadapter", xadapter).Msg("Sending to adapter")
+ if _debug != nil {
+ _debug(" - sending on adapter: %r", xadapter)
+ }
if err := n.Request(NA(xadapter, whoisrtn), NoKWArgs()); err != nil {
return errors.Wrap(err, "error sending Who is router to network")
}
@@ -463,10 +541,16 @@ func (n *NetworkServiceElement) WhoIsRouterToNetwork(adapter *NetworkAdapter, np
func (n *NetworkServiceElement) IAmRouterToNetwork(adapter *NetworkAdapter, npdu NPDU, nlm model.NLMIAmRouterToNetwork) error {
n.log.Debug().Stringer("adapter", adapter).Stringer("npdu", npdu).Stringer("nlm", nlm).Msg("IAmRouterToNetwork")
+ if _debug != nil {
+ _debug("IAmRouterToNetwork %r %r", adapter, npdu)
+ }
// reference the service access point
sap := n.GetElementService().(*NetworkServiceAccessPoint) // TODO: check hard cast here...
n.log.Debug().Stringer("sap", sap).Msg("sap")
+ if _debug != nil {
+ _debug(" - sap: %r", sap)
+ }
// pass along the service access point
if err := sap.UpdateRouterReference(adapter.adapterNet, npdu.GetPDUSource(), nlm.GetDestinationNetworkAddresses()); err != nil {
@@ -476,8 +560,14 @@ func (n *NetworkServiceElement) IAmRouterToNetwork(adapter *NetworkAdapter, npdu
// if we're not a router, skip it
if len(sap.adapters) == 1 {
n.log.Trace().Msg("not a router")
+ if _debug != nil {
+ _debug(" - not a router")
+ }
} else {
n.log.Trace().Msg("forwarding other adapters")
+ if _debug != nil {
+ _debug(" - forwarding to other adapters")
+ }
// Build a broadcast announcement
iamrtn, err := NewIAmRouterToNetwork(NoArgs, NoKWArgs(), WithIAmRouterToNetworkNetworkList(nlm.GetDestinationNetworkAddresses()...))
@@ -490,6 +580,9 @@ func (n *NetworkServiceElement) IAmRouterToNetwork(adapter *NetworkAdapter, npdu
for _, xadapter := range sap.adapters {
if xadapter != adapter {
n.log.Debug().Stringer("xadapter", xadapter).Msg("Sending to adapter")
+ if _debug != nil {
+ _debug(" - sending on adapter: %r", xadapter)
+ }
if err := n.Request(NA(xadapter, iamrtn), NoKWArgs()); err != nil {
return errors.Wrap(err, "error sending I am router to network")
}
@@ -502,6 +595,9 @@ func (n *NetworkServiceElement) IAmRouterToNetwork(adapter *NetworkAdapter, npdu
pendingNpdus, ok := sap.pendingNets[nk(&dnet)]
if ok {
n.log.Debug().Int("pendingNpdus", len(pendingNpdus)).Uint16("dnet", dnet).Msg("pending NPDUs to dnet")
+ if _debug != nil {
+ _debug(" - %d pending to %r", len(pendingNpdus), dnet)
+ }
// delete the references
delete(sap.pendingNets, nk(&dnet))
@@ -509,6 +605,9 @@ func (n *NetworkServiceElement) IAmRouterToNetwork(adapter *NetworkAdapter, npdu
// now reprocess them
for _, pendingNPDU := range pendingNpdus {
n.log.Debug().Stringer("pendingNPDU", pendingNPDU).Msg("sending")
+ if _debug != nil {
+ _debug(" - sending %r", pendingNPDU)
+ }
// the destination is the address of the router
pendingNPDU.SetPDUDestination(npdu.GetPDUSource())
@@ -523,43 +622,73 @@ func (n *NetworkServiceElement) IAmRouterToNetwork(adapter *NetworkAdapter, npdu
return nil
}
-func (n *NetworkServiceElement) ICouldBeRouterToNetwork(adapter *NetworkAdapter, nlm model.NLMICouldBeRouterToNetwork) error {
+func (n *NetworkServiceElement) ICouldBeRouterToNetwork(adapter *NetworkAdapter, npdu NPDU, nlm model.NLMICouldBeRouterToNetwork) error {
+ if _debug != nil {
+ _debug("ICouldBeRouterToNetwork %r %r", adapter, npdu)
+ }
panic("not implemented") // TODO: implement me
}
-func (n *NetworkServiceElement) RejectRouterToNetwork(adapter *NetworkAdapter, nlm model.NLMRejectMessageToNetwork) error {
+func (n *NetworkServiceElement) RejectRouterToNetwork(adapter *NetworkAdapter, npdu NPDU, nlm model.NLMRejectMessageToNetwork) error {
+ if _debug != nil {
+ _debug("RejectMessageToNetwork %r %r", adapter, npdu)
+ }
panic("not implemented") // TODO: implement me
}
-func (n *NetworkServiceElement) RouterBusyToNetwork(adapter *NetworkAdapter, nlm model.NLMRouterBusyToNetwork) error {
+func (n *NetworkServiceElement) RouterBusyToNetwork(adapter *NetworkAdapter, npdu NPDU, nlm model.NLMRouterBusyToNetwork) error {
+ if _debug != nil {
+ _debug("RouterBusyToNetwork %r %r", adapter, npdu)
+ }
panic("not implemented") // TODO: implement me
}
-func (n *NetworkServiceElement) RouterAvailableToNetwork(adapter *NetworkAdapter, nlm model.NLMRouterAvailableToNetwork) error {
+func (n *NetworkServiceElement) RouterAvailableToNetwork(adapter *NetworkAdapter, npdu NPDU, nlm model.NLMRouterAvailableToNetwork) error {
+ if _debug != nil {
+ _debug("RouterAvailableToNetwork %r %r", adapter, npdu)
+ }
panic("not implemented") // TODO: implement me
}
-func (n *NetworkServiceElement) InitalizeRoutingTable(adapter *NetworkAdapter, nlm model.NLMInitializeRoutingTable) error {
+func (n *NetworkServiceElement) InitalizeRoutingTable(adapter *NetworkAdapter, npdu NPDU, nlm model.NLMInitializeRoutingTable) error {
+ if _debug != nil {
+ _debug("InitializeRoutingTable %r %r", adapter, npdu)
+ }
panic("not implemented") // TODO: implement me
}
-func (n *NetworkServiceElement) InitalizeRoutingTableAck(adapter *NetworkAdapter, nlm model.NLMInitializeRoutingTableAck) error {
+func (n *NetworkServiceElement) InitalizeRoutingTableAck(adapter *NetworkAdapter, npdu NPDU, nlm model.NLMInitializeRoutingTableAck) error {
+ if _debug != nil {
+ _debug("InitializeRoutingTableAck %r %r", adapter, npdu)
+ }
panic("not implemented") // TODO: implement me
}
-func (n *NetworkServiceElement) EstablishConnectionToNetwork(adapter *NetworkAdapter, nlm model.NLMEstablishConnectionToNetwork) error {
+func (n *NetworkServiceElement) EstablishConnectionToNetwork(adapter *NetworkAdapter, npdu NPDU, nlm model.NLMEstablishConnectionToNetwork) error {
+ if _debug != nil {
+ _debug("EstablishConnectionToNetwork %r %r", adapter, npdu)
+ }
panic("not implemented") // TODO: implement me
}
-func (n *NetworkServiceElement) DisconnectConnectionToNetwork(adapter *NetworkAdapter, nlm model.NLMDisconnectConnectionToNetwork) error {
+func (n *NetworkServiceElement) DisconnectConnectionToNetwork(adapter *NetworkAdapter, npdu NPDU, nlm model.NLMDisconnectConnectionToNetwork) error {
+ if _debug != nil {
+ _debug("DisconnectConnectionToNetwork %r %r", adapter, npdu)
+ }
panic("not implemented") // TODO: implement me
}
-func (n *NetworkServiceElement) WhatIsNetworkNumber(adapter *NetworkAdapter, nlm model.NLMWhatIsNetworkNumber) error {
+func (n *NetworkServiceElement) WhatIsNetworkNumber(adapter *NetworkAdapter, npdu NPDU, nlm model.NLMWhatIsNetworkNumber) error {
+ if _debug != nil {
+ _debug("WhatIsNetworkNumber %r %r", adapter, npdu)
+ }
panic("not implemented") // TODO: implement me
}
-func (n *NetworkServiceElement) NetworkNumberIs(adapter *NetworkAdapter, nlm model.NLMNetworkNumberIs) error {
+func (n *NetworkServiceElement) NetworkNumberIs(adapter *NetworkAdapter, npdu NPDU, nlm model.NLMNetworkNumberIs) error {
+ if _debug != nil {
+ _debug("NetworkNumberIs %r %r", adapter, npdu)
+ }
panic("not implemented") // TODO: implement me
}
diff --git a/plc4go/internal/bacnetip/bacgopes/netservice/netservice_RouterInfoCache.go b/plc4go/internal/bacnetip/bacgopes/netservice/netservice_RouterInfoCache.go
index f97510c0e1..3daec898b3 100644
--- a/plc4go/internal/bacnetip/bacgopes/netservice/netservice_RouterInfoCache.go
+++ b/plc4go/internal/bacnetip/bacgopes/netservice/netservice_RouterInfoCache.go
@@ -20,6 +20,8 @@
package netservice
import (
+ "maps"
+
"github.com/pkg/errors"
"github.com/rs/zerolog"
@@ -79,6 +81,9 @@ type RouterInfoCache struct {
func NewRouterInfoCache(localLog zerolog.Logger) *RouterInfoCache {
localLog.Trace().Msg("NewRouterInfoCache")
+ if _debug != nil {
+ _debug("__init__")
+ }
return &RouterInfoCache{
routers: map[netKey]*Router{},
pathInfo: map[snetDnetTuple]*RouterInfo{},
@@ -89,9 +94,15 @@ func NewRouterInfoCache(localLog zerolog.Logger) *RouterInfoCache {
func (n *RouterInfoCache) GetRouterInfo(snet, dnet netKey) *RouterInfo {
n.log.Debug().Stringer("snet", snet).Stringer("dnet", dnet).Msg("GetRouterInfo")
+ if _debug != nil {
+ _debug("get_routerInfo %r %r", snet, dnet)
+ }
// return the network and address
routerInfo, _ := n.pathInfo[snetDnetTuple{snet, dnet}]
+ if _debug != nil {
+ _debug(" - routerInfo: %r", routerInfo)
+ }
return routerInfo
}
@@ -100,6 +111,9 @@ func (n *RouterInfoCache) UpdateRouterInfo(snet netKey, address *Address, dnets
status = ToPtr(ROUTER_AVAILABLE)
}
n.log.Debug().Stringer("snet", snet).Stringer("dnet", address).Uints16("dnets", dnets).Msg("UpdateRouterInfo")
+ if _debug != nil {
+ _debug("update_routerInfo %r %r %r", snet, address, dnets)
+ }
var existingRouterInfo *RouterInfo
if r, ok := n.routers[snet]; ok {
@@ -125,6 +139,9 @@ func (n *RouterInfoCache) UpdateRouterInfo(snet netKey, address *Address, dnets
Uint16("dnet", dnet).
Stringer("routerInfoAddress", routerInfo.address).
Msg("del path: snet -> dnet via routerInfoAddress")
+ if _debug != nil {
+ _debug(" - del path: %r -> %r via %r", snet, dnet, routerInfo.address)
+ }
}
}
if len(routerInfo.dnets) == 0 {
@@ -133,6 +150,9 @@ func (n *RouterInfoCache) UpdateRouterInfo(snet netKey, address *Address, dnets
Stringer("snet", snet).
Stringer("routerInfoAddress", routerInfo.address).
Msg("no dnets: snet via routerInfoAddress")
+ if _debug != nil {
+ _debug(" - no dnets: %r via %r", snet, routerInfo.address)
+ }
}
}
@@ -154,6 +174,9 @@ func (n *RouterInfoCache) UpdateRouterInfo(snet netKey, address *Address, dnets
Uint16("dnet", dnet).
Stringer("routerInfoAddress", routerInfo.address).
Msg("add path: snet -> dnet via routerInfoAddress")
+ if _debug != nil {
+ _debug(" - add path: %r -> %r via %r", snet, dnet, routerInfo.address)
+ }
routerInfo.dnets[nk(&dnet)] = *status
}
} else {
@@ -164,6 +187,9 @@ func (n *RouterInfoCache) UpdateRouterInfo(snet netKey, address *Address, dnets
Stringer("snet", snet).
Uint16("dnet", dnet).
Msg("add path: snet -> dnet")
+ if _debug != nil {
+ _debug(" - add path: %r -> %r", snet, dnet)
+ }
}
existingRouterInfo.dnets[nk(&dnet)] = *status
}
@@ -173,6 +199,9 @@ func (n *RouterInfoCache) UpdateRouterInfo(snet netKey, address *Address, dnets
func (n *RouterInfoCache) UpdateRouterStatus(snet netKey, address *Address, status RouterStatus) error {
n.log.Debug().Stringer("snet", snet).Stringer("dnet", address).Stringer("status", status).Msg("UpdateRouterStatus")
+ if _debug != nil {
+ _debug("update_router_status %r %r %r", snet, address, status)
+ }
var existingRouterInfo *RouterInfo
if r, ok := n.routers[snet]; ok {
@@ -181,16 +210,25 @@ func (n *RouterInfoCache) UpdateRouterStatus(snet netKey, address *Address, stat
if existingRouterInfo == nil {
n.log.Trace().Msg("not a router we know about")
+ if _debug != nil {
+ _debug(" - not a router we know about")
+ }
return nil
}
existingRouterInfo.status = status
n.log.Trace().Msg("status updated")
+ if _debug != nil {
+ _debug(" - status updated")
+ }
return nil
}
func (n *RouterInfoCache) DeleteRouterInfo(snet netKey, address *Address, dnets []uint16) error {
n.log.Debug().Stringer("snet", snet).Stringer("dnet", address).Uints16("dnets", dnets).Msg("DeleteRouterInfo")
+ if _debug != nil {
+ _debug("delete_routerInfo %r %r %r", dnets)
+ }
if address == nil && len(dnets) == 0 {
return errors.New("inconsistent parameters")
}
@@ -203,6 +241,9 @@ func (n *RouterInfoCache) DeleteRouterInfo(snet netKey, address *Address, dnets
}
if routerInfo == nil {
n.log.Trace().Msg("no router info")
+ if _debug != nil {
+ _debug(" - no route info")
+ }
} else {
for dnet := range routerInfo.dnets {
if !dnet.IsNil {
@@ -215,6 +256,9 @@ func (n *RouterInfoCache) DeleteRouterInfo(snet netKey, address *Address, dnets
Uint16("dnet", dnet).
Stringer("routerInfoAddress", routerInfo.address).
Msg("del path: snet -> dnet via routerInfoAddress")
+ if _debug != nil {
+ _debug(" - del path: %r -> %r via %r", snet, dnet, routerInfo.address)
+ }
}
}
return nil
@@ -240,6 +284,9 @@ func (n *RouterInfoCache) DeleteRouterInfo(snet netKey, address *Address, dnets
Uint16("dnet", dnet).
Stringer("routerInfoAddress", routerInfo.address).
Msg("del path: snet -> dnet via routerInfoAddress")
+ if _debug != nil {
+ _debug(" - del path: %r -> %r via %r", snet, dnet, routerInfo.address)
+ }
}
}
if len(routerInfo.dnets) == 0 {
@@ -248,6 +295,9 @@ func (n *RouterInfoCache) DeleteRouterInfo(snet netKey, address *Address, dnets
Stringer("snet", snet).
Stringer("routerInfoAddress", routerInfo.address).
Msg("no dnets: snet via routerInfoAddress")
+ if _debug != nil {
+ _debug(" - no dnets: %r via %r", snet, routerInfo.address)
+ }
}
}
return nil
@@ -255,9 +305,15 @@ func (n *RouterInfoCache) DeleteRouterInfo(snet netKey, address *Address, dnets
func (n *RouterInfoCache) UpdateSourceNetwork(oldSnet netKey, newSnet netKey) error {
n.log.Debug().Stringer("oldSnet", oldSnet).Stringer("newSnet", newSnet).Msg("UpdateSourceNetwork")
+ if _debug != nil {
+ _debug("update_source_network %r %r", oldSnet, newSnet)
+ }
if _, ok := n.routers[oldSnet]; !ok {
n.log.Debug().Interface("routers", n.routers).Msg("No router references")
+ if _debug != nil {
+ _debug(" - no router references: %r", maps.Keys(n.routers))
+ }
return nil
}