Skip to content

Refactor network manager#528

Open
MykolaSuperman wants to merge 10 commits intoaosedge:feature_release_9.1from
MykolaSuperman:refactor_network_manager
Open

Refactor network manager#528
MykolaSuperman wants to merge 10 commits intoaosedge:feature_release_9.1from
MykolaSuperman:refactor_network_manager

Conversation

@MykolaSuperman
Copy link

No description provided.

@MykolaSuperman MykolaSuperman force-pushed the refactor_network_manager branch from 529ffc6 to f022560 Compare March 6, 2026 10:21
@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

❌ Patch coverage is 91.26731% with 82 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.17%. Comparing base (79d1152) to head (af7d8f3).

Files with missing lines Patch % Lines
src/core/sm/networkmanager/networkmanager.cpp 77.77% 80 Missing ⚠️
...rc/core/sm/networkmanager/tests/networkmanager.cpp 99.57% 2 Missing ⚠️
Additional details and impacted files
@@                   Coverage Diff                   @@
##           feature_release_9.1     #528      +/-   ##
=======================================================
- Coverage                85.25%   85.17%   -0.08%     
=======================================================
  Files                      311      309       -2     
  Lines                    27938    27965      +27     
  Branches                  3762     3745      -17     
=======================================================
+ Hits                     23819    23820       +1     
- Misses                    4119     4145      +26     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MykolaSuperman MykolaSuperman force-pushed the refactor_network_manager branch 7 times, most recently from b90964f to 1aede72 Compare March 9, 2026 11:03
@@ -0,0 +1,75 @@
/*
* Copyright (C) 2025 EPAM Systems, Inc.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2026

/**
* Network provider interface (SM -> CM network service).
*/
class NetworkProviderItf {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add unit test for this interface and network.md file that describes the purpose if this interfae.

* SPDX-License-Identifier: Apache-2.0
*/

#ifndef AOS_CORE_COMMON_NETWORK_ITF_NETWORKPROVIDER_HPP_
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it is part of networkmanager then it should be in networkmanager folder and networkmanager namespace.


void Balancer::Init(InstanceManager& instanceManager, imagemanager::ItemInfoProviderItf& itemInfoProvider,
oci::OCISpecItf& ociSpec, NodeManager& nodeManager, MonitoringProviderItf& monitorProvider,
InstanceRunnerItf& runner, NetworkManager& networkManager)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do launcher unit tests work after these changes?

StaticString<cSubnetLen> mSubnet;
StaticString<cIPLen> mIP;
uint64_t mVlanID {};
struct NetworkServiceData {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have services any more. Rename to UpdateItemNetworkParameters.

Shortcut parameters to params:

NetworkParams
InstanceNetworkParams
UpdateItemNetworkParams

Can InstanceNetworkParams have the following fields:

struct InstanceNetworkParams {
    NetworkParams mNetworkParams;
    StaticArray<StaticString<cIPLen>, cMaxNumDNSServers> mDNSServers;
    StaticArray<FirewallRule, cMaxNumFirewallRules>      mFirewallRules;
   ...

?

* @param networks network parameters.
* @return Error.
* @param period traffic period.
* @return Error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

period at the end

LOG_DBG() << "Update networks";
LOG_DBG() << "Get system traffic";

return AOS_ERROR_WRAP(mNetMonitor->GetSystemTraffic(inputTraffic, outputTraffic));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not put operators in macro. It reduces readability.

{
LOG_DBG() << "Get instance traffic" << Log::Field("instanceID", instanceID);

return AOS_ERROR_WRAP(mNetMonitor->GetInstanceTraffic(instanceID, inputTraffic, outputTraffic));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

*/
Error SetTrafficPeriod(TrafficPeriod period) override;

Error PrepareInstanceNetwork(const String& instanceID, const String& networkID,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment public API

Error PrepareInstanceNetwork(const String& instanceID, const String& networkID,
const InstanceNetworkParameters& instanceNetworkParameters, const NetworkServiceData& serviceData) override;

Error CleanupInstanceNetwork(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@MykolaSuperman MykolaSuperman force-pushed the refactor_network_manager branch 5 times, most recently from c3523c3 to 3d896e4 Compare March 18, 2026 14:27
/**
* Instance network runtime parameters for Start (not stored in DB).
*/
struct InstanceNetworkRuntimeParameters {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InstanceNetworkRuntimeParams

@MykolaSuperman MykolaSuperman force-pushed the refactor_network_manager branch 3 times, most recently from 1a1bfd6 to 550fa1e Compare March 20, 2026 14:24
- NetworkParameters -> NetworkParams
- InstanceNetworkParameters -> InstanceNetworkAllocation
- UpdateNetworkParameters -> UpdateItemNetworkParams (NetworkServiceData)

Signed-off-by: Mykola Solianko <mykola_solianko@epam.com>
@MykolaSuperman MykolaSuperman force-pushed the refactor_network_manager branch from f844bfb to 5c3686d Compare March 25, 2026 14:52
Mykola Solianko added 9 commits March 25, 2026 16:54
Add network provider interface for SM to communicate with CM
for network allocation and release operations.

Signed-off-by: Mykola Solianko <mykola_solianko@epam.com>
- Remove CM networkmanager module (moved to SM-driven model)
- Update CM launcher to remove network management
- Update smcontroller to use NetworkProviderItf

Signed-off-by: Mykola Solianko <mykola_solianko@epam.com>
Add types.hpp with:
- InstanceNetworkConfig: network config for Create (stored in DB)
- InstanceNetworkRuntimeParameters: runtime paths for Start

Signed-off-by: Mykola Solianko <mykola_solianko@epam.com>
Replace PrepareInstanceNetwork/CleanupInstanceNetwork with 4 methods:
- CreateInstanceNetwork: CM allocation + DB (idempotent)
- StartInstanceNetwork: physical setup from cached params
- StopInstanceNetwork: physical cleanup, clears bridge/VLAN if last
- ReleaseInstanceNetwork: DB + CM release, requires Stop first

Key changes:
- InstanceNetworkInfo extended with InstanceNetworkConfig and
  InstanceNetworkAllocation for offline Start after reboot
- Init no longer removes instance network info from DB
- Init no longer creates bridge/VLAN (deferred to Start)
- EnsureNodeNetwork split into logical (CM) and physical parts
- Thread-safe access to mInstanceNetworkInfos cache
- networkID validation in Start/Stop/Release

Signed-off-by: Mykola Solianko <mykola_solianko@epam.com>
- Update all NM tests to use Create+Start / Stop+Release
- Add tests: networkID mismatch, Release without Stop, idempotent Create
- Update NetworkManagerMock with 4 methods
- Add NetworkProviderMock
- Update launcher tests for new API

Signed-off-by: Mykola Solianko <mykola_solianko@epam.com>
- Add PendingFirewallUpdate struct to network.hpp (instanceIdent + firewall rules)
- Add PendingUpdateHandlerItf to networkprovider.hpp for deferred firewall
  update notifications between CM and SM
- Add PendingUpdateHandlerMock for testing

Signed-off-by: Mykola Solianko <mykola_solianko@epam.com>
- Add UpdateFirewall to CNIItf interface for firewall-only CNI updates
  (DEL old + ADD new rules while preserving bridge/DNS/bandwidth cache)
- Update CNIMock with UpdateFirewall

Signed-off-by: Mykola Solianko <mykola_solianko@epam.com>
- NetworkManagerItf inherits PendingUpdateHandlerItf
- Add OnPendingFirewallUpdate: receives resolved pending rules from CM,
  updates storage and RAM cache atomically (storage first), applies
  firewall-only CNI update for running instances
- Add UpdateInstanceFirewall: retrieves cached CNI config, rebuilds
  firewall plugin config, calls CNI::UpdateFirewall
- Validate nodeID matches before processing update
- Update NetworkManagerMock with OnPendingFirewallUpdate

Signed-off-by: Mykola Solianko <mykola_solianko@epam.com>
- OnPendingFirewallUpdate_UpdatesFirewallRules: notification updates
  rules in storage for non-running instance
- OnPendingFirewallUpdate_RunningInstance_CallsCNIUpdate: notification
  triggers CNI UpdateFirewall for running instance

Signed-off-by: Mykola Solianko <mykola_solianko@epam.com>
@MykolaSuperman MykolaSuperman force-pushed the refactor_network_manager branch from 5c3686d to af7d8f3 Compare March 25, 2026 14:55
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants