Skip to content

Commit 943ae5b

Browse files
add a new helper function to simplify naming and id search for path segments and connection events
Signed-off-by: Denis Tingaikin <[email protected]>
1 parent 9785eac commit 943ae5b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pkg/api/networkservice/connection_event_helpers.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,13 @@ import "google.golang.org/protobuf/proto"
2222
func (x *ConnectionEvent) Clone() *ConnectionEvent {
2323
return proto.Clone(x).(*ConnectionEvent)
2424
}
25+
26+
// GetEventSenderName returns name of the segment from the path who send the event
27+
func (x *ConnectionEvent) GetEventSenderName() string {
28+
for v, k := range x.GetConnections() {
29+
if segment := k.GetPathSegmentById(v); segment != nil {
30+
return segment.GetName()
31+
}
32+
}
33+
return "unknown"
34+
}

pkg/api/networkservice/connection_helpers.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ func (x *Connection) MatchesMonitorScopeSelector(selector *MonitorScopeSelector)
160160
return false
161161
}
162162

163+
// GetPathSegmentById gets the path segment by passed id
164+
func (x *Connection) GetPathSegmentById(id string) *PathSegment {
165+
for _, segment := range x.GetPath().GetPathSegments() {
166+
if segment.GetId() == id {
167+
return segment
168+
}
169+
}
170+
return nil
171+
}
172+
163173
// GetCurrentPathSegment - Get the current path segment of the connection
164174
func (x *Connection) GetCurrentPathSegment() *PathSegment {
165175
if x == nil {

0 commit comments

Comments
 (0)