1 // 2 // Copyright (c) 2010-2022 Antmicro 3 // Copyright (c) 2011-2015 Realtime Embedded 4 // 5 // This file is licensed under the MIT License. 6 // Full license text is available in 'licenses/MIT.txt'. 7 // 8 using System; 9 using Antmicro.Renode.Core; 10 using Antmicro.Renode.Peripherals.Network; 11 using Antmicro.Renode.Utilities; 12 using Antmicro.Renode.Exceptions; 13 using System.IO; 14 15 namespace Antmicro.Renode.HostInterfaces.Network 16 { 17 public static class TapExtensions 18 { CreateAndGetTap(this Emulation emulation, string hostInterfaceName, string name, bool persistent = false)19 public static IMACInterface CreateAndGetTap(this Emulation emulation, string hostInterfaceName, string name, bool persistent = false) 20 { 21 ITapInterface result; 22 #if PLATFORM_WINDOWS 23 result = new WindowsTapInterface(hostInterfaceName); 24 #elif PLATFORM_OSX 25 if(persistent) 26 { 27 throw new RecoverableException("Persitent TAP is not available on OS X."); 28 } 29 result = new OsXTapInterface(hostInterfaceName); 30 #elif PLATFORM_LINUX 31 result = new LinuxTapInterface(hostInterfaceName, persistent); 32 #endif 33 34 emulation.HostMachine.AddHostMachineElement(result, name); 35 return result; 36 } 37 CreateTap(this Emulation emulation, string hostInterfaceName, string name, bool persistent = false)38 public static void CreateTap(this Emulation emulation, string hostInterfaceName, string name, bool persistent = false) 39 { 40 CreateAndGetTap(emulation, hostInterfaceName, name, persistent); 41 } 42 } 43 } 44 45