Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pkg/api/networkservice/connection_event_helpers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020 Cisco and/or its affiliates.
// Copyright (c) 2020-2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -22,3 +22,13 @@ import "google.golang.org/protobuf/proto"
func (x *ConnectionEvent) Clone() *ConnectionEvent {
return proto.Clone(x).(*ConnectionEvent)
}

// GetEventSenderName returns name of the segment from the path who send the event
func (x *ConnectionEvent) GetEventSenderName() string {
for v, k := range x.GetConnections() {
if segment := k.GetPathSegmentByID(v); segment != nil {
return segment.GetName()
}
}
return "unknown"
}
12 changes: 12 additions & 0 deletions pkg/api/networkservice/connection_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// Copyright (c) 2021 Doc.ai and/or its affiliates.
//
// Copyright (c) 2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -160,6 +162,16 @@ func (x *Connection) MatchesMonitorScopeSelector(selector *MonitorScopeSelector)
return false
}

// GetPathSegmentByID gets the path segment by passed id
func (x *Connection) GetPathSegmentByID(id string) *PathSegment {
for _, segment := range x.GetPath().GetPathSegments() {
if segment.GetId() == id {
return segment
}
}
return nil
}

// GetCurrentPathSegment - Get the current path segment of the connection
func (x *Connection) GetCurrentPathSegment() *PathSegment {
if x == nil {
Expand Down