1#!/usr/bin/env python3 2# 3# Copyright 2021 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17from acts import logger 18from acts import signals 19 20 21class NetstackControllerError(signals.ControllerError): 22 pass 23 24 25class NetstackController: 26 """Contains methods related to netstack, to be used in FuchsiaDevice object""" 27 28 def __init__(self, fuchsia_device): 29 self.device = fuchsia_device 30 self.log = logger.create_tagged_trace_logger( 31 'NetstackController for FuchsiaDevice | %s' % self.device.ip) 32 33 def list_interfaces(self): 34 """Retrieve netstack interfaces from netstack facade 35 36 Returns: 37 List of dicts, one for each interface, containing interface 38 information 39 """ 40 response = self.device.sl4f.netstack_lib.netstackListInterfaces() 41 if response.get('error'): 42 raise NetstackControllerError( 43 'Failed to get network interfaces list: %s' % 44 response['error']) 45 return response['result'] 46