Windows Cert Testing (#943)

* PR for cert test interface for Windows driver model.
This commit is contained in:
Nick Banks
2016-11-29 12:10:34 -08:00
committed by Jonathan Hui
parent c2598bf4c9
commit 24b98dbb85
28 changed files with 4722 additions and 604 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ certutil -addstore TrustedPublisher otLwf.cer
cd otLwf
REM Install the NDSI LWF driver, otLwf.sys
REM Install the NDIS LWF driver, otLwf.sys
netcfg.exe -v -l otlwf.inf -c s -i otLwf
+4
View File
@@ -34,6 +34,10 @@ REM Query the driver state
sc query otlwf
REM Run the basic driver test
otTestRunner.exe ..\tests\scripts\thread-cert Test_otLwf* appveyor
REM Grab the logs
mkdir logs
-6
View File
@@ -59,12 +59,6 @@
%(AdditionalLibraryDirectories);
$(VCInstallDir)UnitTest\lib;
</AdditionalLibraryDirectories>
<AdditionalDependencies>
%(AdditionalDependencies);
..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread.lib;
..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread-ncp-uart.lib;
..\..\build\bin\$(Platform)\$(Configuration)\lib\mbedtls.lib;
</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
+30
View File
@@ -48,6 +48,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "otLwf", "otLwf.vcxproj", "{
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "otApi", "otApi.vcxproj", "{ED0EA262-C222-42C7-98D3-E70C72978ED2}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "otNodeApi", "otNodeApi.vcxproj", "{B7C6F344-7287-4930-AF38-223622BD8CBB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "otTestRunner", "otTestRunner.csproj", "{D5577E51-FA31-4802-8669-1DB32805935E}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenThread", "OpenThread.vcxproj", "{F8C22844-9B93-4978-80DF-8AF2B37A7ABB}"
ProjectSection(ProjectDependencies) = postProject
{ED0EA262-C222-42C7-98D3-E70C72978ED2} = {ED0EA262-C222-42C7-98D3-E70C72978ED2}
@@ -245,6 +249,30 @@ Global
{ED0EA262-C222-42C7-98D3-E70C72978ED2}.Release|x64.Build.0 = Release|x64
{ED0EA262-C222-42C7-98D3-E70C72978ED2}.Release|x86.ActiveCfg = Release|Win32
{ED0EA262-C222-42C7-98D3-E70C72978ED2}.Release|x86.Build.0 = Release|Win32
{B7C6F344-7287-4930-AF38-223622BD8CBB}.Debug|ARM.ActiveCfg = Debug|ARM
{B7C6F344-7287-4930-AF38-223622BD8CBB}.Debug|ARM.Build.0 = Debug|ARM
{B7C6F344-7287-4930-AF38-223622BD8CBB}.Debug|x64.ActiveCfg = Debug|x64
{B7C6F344-7287-4930-AF38-223622BD8CBB}.Debug|x64.Build.0 = Debug|x64
{B7C6F344-7287-4930-AF38-223622BD8CBB}.Debug|x86.ActiveCfg = Debug|Win32
{B7C6F344-7287-4930-AF38-223622BD8CBB}.Debug|x86.Build.0 = Debug|Win32
{B7C6F344-7287-4930-AF38-223622BD8CBB}.Release|ARM.ActiveCfg = Release|ARM
{B7C6F344-7287-4930-AF38-223622BD8CBB}.Release|ARM.Build.0 = Release|ARM
{B7C6F344-7287-4930-AF38-223622BD8CBB}.Release|x64.ActiveCfg = Release|x64
{B7C6F344-7287-4930-AF38-223622BD8CBB}.Release|x64.Build.0 = Release|x64
{B7C6F344-7287-4930-AF38-223622BD8CBB}.Release|x86.ActiveCfg = Release|Win32
{B7C6F344-7287-4930-AF38-223622BD8CBB}.Release|x86.Build.0 = Release|Win32
{D5577E51-FA31-4802-8669-1DB32805935E}.Debug|ARM.ActiveCfg = Debug|Any CPU
{D5577E51-FA31-4802-8669-1DB32805935E}.Debug|ARM.Build.0 = Debug|Any CPU
{D5577E51-FA31-4802-8669-1DB32805935E}.Debug|x64.ActiveCfg = Debug|x64
{D5577E51-FA31-4802-8669-1DB32805935E}.Debug|x64.Build.0 = Debug|x64
{D5577E51-FA31-4802-8669-1DB32805935E}.Debug|x86.ActiveCfg = Debug|Win32
{D5577E51-FA31-4802-8669-1DB32805935E}.Debug|x86.Build.0 = Debug|Win32
{D5577E51-FA31-4802-8669-1DB32805935E}.Release|ARM.ActiveCfg = Release|Any CPU
{D5577E51-FA31-4802-8669-1DB32805935E}.Release|ARM.Build.0 = Release|Any CPU
{D5577E51-FA31-4802-8669-1DB32805935E}.Release|x64.ActiveCfg = Release|x64
{D5577E51-FA31-4802-8669-1DB32805935E}.Release|x64.Build.0 = Release|x64
{D5577E51-FA31-4802-8669-1DB32805935E}.Release|x86.ActiveCfg = Release|Win32
{D5577E51-FA31-4802-8669-1DB32805935E}.Release|x86.Build.0 = Release|Win32
{F8C22844-9B93-4978-80DF-8AF2B37A7ABB}.Debug|ARM.ActiveCfg = Debug|ARM
{F8C22844-9B93-4978-80DF-8AF2B37A7ABB}.Debug|ARM.Build.0 = Debug|ARM
{F8C22844-9B93-4978-80DF-8AF2B37A7ABB}.Debug|ARM.Deploy.0 = Debug|ARM
@@ -282,6 +310,8 @@ Global
{9EEF9DCD-EA8F-4154-BD02-AB2B31CEC324} = {76EA541E-CAB1-4DB5-A39F-E3DB2A78CDDD}
{3F1F7F6C-2A33-4635-9880-08FC5BC4E435} = {61E8A4A0-8138-49DB-97B4-3BEC87C8E133}
{ED0EA262-C222-42C7-98D3-E70C72978ED2} = {61E8A4A0-8138-49DB-97B4-3BEC87C8E133}
{B7C6F344-7287-4930-AF38-223622BD8CBB} = {61E8A4A0-8138-49DB-97B4-3BEC87C8E133}
{D5577E51-FA31-4802-8669-1DB32805935E} = {35F6AB71-5BD2-4D53-8A51-D75CCD4CCC3D}
{F8C22844-9B93-4978-80DF-8AF2B37A7ABB} = {76EA541E-CAB1-4DB5-A39F-E3DB2A78CDDD}
EndGlobalSection
EndGlobal
+1 -6
View File
@@ -52,12 +52,7 @@
<Link>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>
%(AdditionalDependencies);
ws2_32.lib;
..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread.lib;
..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread-cli.lib;
..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread-windows.lib;
..\..\build\bin\$(Platform)\$(Configuration)\lib\mbedtls.lib;
mincore.lib;
</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
+1 -6
View File
@@ -52,12 +52,7 @@
<Link>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>
%(AdditionalDependencies);
ws2_32.lib;
..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread.lib;
..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread-ncp-spi.lib;
..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread-windows.lib;
..\..\build\bin\$(Platform)\$(Configuration)\lib\mbedtls.lib;
mincore.lib;
</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
+1 -6
View File
@@ -52,12 +52,7 @@
<Link>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>
%(AdditionalDependencies);
ws2_32.lib;
..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread.lib;
..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread-ncp-uart.lib;
..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread-windows.lib;
..\..\build\bin\$(Platform)\$(Configuration)\lib\mbedtls.lib;
mincore.lib;
</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
+1 -11
View File
@@ -39,7 +39,6 @@
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>
%(PreprocessorDefinitions);
WIN32;_WINDOWS;_USRDLL;
OTAPI_EXPORTS;
</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
@@ -53,17 +52,8 @@
<WppScanConfigurationData>..\..\include\platform\logging-windows.h</WppScanConfigurationData>
<WppModuleName>otApi</WppModuleName>
<EnablePREfast>true</EnablePREfast>
<ExceptionHandling Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Sync</ExceptionHandling>
<ExceptionHandling Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Sync</ExceptionHandling>
<ExceptionHandling Condition="'$(Platform)'=='ARM'">Sync</ExceptionHandling>
</ClCompile>
<Link>
<AdditionalDependencies>
onecore.lib;
onecoreuap.lib;
mincore.lib;
ntdll.lib;
</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\examples\drivers\windows\otApi\precomp.h" />
+4 -6
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="openthread.configuration.props" />
<Import Project="openthread.configuration.props" />
<PropertyGroup Label="Globals">
<ProjectGuid>{3F1F7F6C-2A33-4635-9880-08FC5BC4E435}</ProjectGuid>
<TemplateGuid>{8b1800b9-d017-4029-9785-13ef5e5b328e}</TemplateGuid>
@@ -76,8 +76,6 @@
netio.lib;
uuid.lib;
cng.lib;
..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread_k.lib;
..\..\build\bin\$(Platform)\$(Configuration)\lib\mbedtls_k.lib
</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
@@ -88,6 +86,7 @@
<ClCompile Include="..\..\examples\drivers\windows\otLwf\driver.c" />
<ClCompile Include="..\..\examples\drivers\windows\otLwf\eventprocessing.c" />
<ClCompile Include="..\..\examples\drivers\windows\otLwf\iocontrol.c" />
<ClCompile Include="..\..\examples\drivers\windows\otLwf\settings.c" />
<ClCompile Include="..\..\examples\drivers\windows\otLwf\oid.c" />
<ClCompile Include="..\..\examples\drivers\windows\otLwf\precomp.c">
<AdditionalIncludeDirectories>..;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
@@ -98,9 +97,6 @@
<ClCompile Include="..\..\examples\drivers\windows\otLwf\filter.c" />
<ClCompile Include="..\..\examples\drivers\windows\otLwf\device.c" />
<ClCompile Include="..\..\examples\drivers\windows\otLwf\radio.c" />
<ClCompile Include="..\..\examples\drivers\windows\otLwf\settings.c" />
<ResourceCompile Include="..\..\examples\drivers\windows\otLwf\filter.rc" />
<Inf Include="..\..\examples\drivers\windows\otLwf\otLwf.inf" />
<ClInclude Include="..\..\examples\drivers\windows\otLwf\device.h" />
<ClInclude Include="..\..\examples\drivers\windows\otLwf\driver.h" />
<ClInclude Include="..\..\examples\drivers\windows\otLwf\iocontrol.h" />
@@ -109,6 +105,8 @@
<ClInclude Include="..\..\examples\drivers\windows\otLwf\radio.h" />
<ClInclude Include="..\..\examples\drivers\windows\otLwf\precomp.h" />
<ClInclude Include="..\..\examples\drivers\windows\otLwf\filter.h" />
<ResourceCompile Include="..\..\examples\drivers\windows\otLwf\filter.rc" />
<Inf Include="..\..\examples\drivers\windows\otLwf\otLwf.inf" />
</ItemGroup>
<ItemGroup>
<FilesToPackage Include="$(TargetPath)" />
+77
View File
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="openthread.configuration.props" />
<PropertyGroup Label="Globals">
<ProjectGuid>{B7C6F344-7287-4930-AF38-223622BD8CBB}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Thread</RootNamespace>
<MinimumVisualStudioVersion>12.0</MinimumVisualStudioVersion>
<DriverTargetPlatform>Universal</DriverTargetPlatform>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>WindowsApplicationForDrivers10.0</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>WindowsApplicationForDrivers10.0</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings" />
<ImportGroup Label="Shared" />
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<IntDir>..\..\build\obj\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
<OutDir>..\..\build\bin\$(Platform)\$(Configuration)\dll\</OutDir>
<RunCodeAnalysis>true</RunCodeAnalysis>
<ApiValidator_Enable>false</ApiValidator_Enable>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>
%(PreprocessorDefinitions);
OTAPI_EXPORTS;
</PreprocessorDefinitions>
<AdditionalIncludeDirectories>
%(AdditionalIncludeDirectories);
..\..\examples\drivers\windows\include;
..\..\examples\drivers\windows\otApi;
..\..\include;
</AdditionalIncludeDirectories>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<WppEnabled>true</WppEnabled>
<WppScanConfigurationData>..\..\include\platform\logging-windows.h</WppScanConfigurationData>
<WppModuleName>otNodeApi</WppModuleName>
<EnablePREfast>true</EnablePREfast>
<ExceptionHandling Condition="'$(Platform)'=='ARM'">Sync</ExceptionHandling>
</ClCompile>
<Link>
<AdditionalDependencies>
ntdll.lib;
</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\examples\drivers\windows\otNodeApi\precomp.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\examples\drivers\windows\otNodeApi\dllmain.cpp" />
<ClCompile Include="..\..\examples\drivers\windows\otNodeApi\otNodeApi.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="otApi.vcxproj">
<Project>{ed0ea262-c222-42c7-98d3-e70c72978ed2}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\examples\drivers\windows\otNodeApi\otNodeApi.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\examples\drivers\windows\otNodeApi\dllmain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\examples\drivers\windows\otNodeApi\precomp.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
+112
View File
@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D5577E51-FA31-4802-8669-1DB32805935E}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>otTestRunner</RootNamespace>
<AssemblyName>otTestRunner</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<IntermediateOutputPath>..\..\build\obj\$(Platform)\$(Configuration)\otTestRunner\</IntermediateOutputPath>
<BaseIntermediateOutputPath>..\..\build\obj\$(Platform)\$(Configuration)\otTestRunner\</BaseIntermediateOutputPath>
<OutputPath>..\..\build\bin\$(Platform)\$(Configuration)\exe\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<IntermediateOutputPath>..\..\build\obj\$(Platform)\$(Configuration)\otTestRunner\</IntermediateOutputPath>
<BaseIntermediateOutputPath>..\..\build\obj\$(Platform)\$(Configuration)\otTestRunner\</BaseIntermediateOutputPath>
<OutputPath>..\..\build\bin\$(Platform)\$(Configuration)\exe\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<IntermediateOutputPath>..\..\build\obj\$(Platform)\$(Configuration)\otTestRunner\</IntermediateOutputPath>
<BaseIntermediateOutputPath>..\..\build\obj\$(Platform)\$(Configuration)\otTestRunner\</BaseIntermediateOutputPath>
<OutputPath>..\..\build\bin\$(Platform)\$(Configuration)\exe\</OutputPath>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<IntermediateOutputPath>..\..\build\obj\$(Platform)\$(Configuration)\otTestRunner\</IntermediateOutputPath>
<BaseIntermediateOutputPath>..\..\build\obj\$(Platform)\$(Configuration)\otTestRunner\</BaseIntermediateOutputPath>
<OutputPath>..\..\build\bin\$(Platform)\$(Configuration)\exe\</OutputPath>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|Win32'">
<DebugSymbols>true</DebugSymbols>
<IntermediateOutputPath>..\..\build\obj\$(Platform)\$(Configuration)\otTestRunner\</IntermediateOutputPath>
<BaseIntermediateOutputPath>..\..\build\obj\$(Platform)\$(Configuration)\otTestRunner\</BaseIntermediateOutputPath>
<OutputPath>..\..\build\bin\$(Platform)\$(Configuration)\exe\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|Win32'">
<IntermediateOutputPath>..\..\build\obj\$(Platform)\$(Configuration)\otTestRunner\</IntermediateOutputPath>
<BaseIntermediateOutputPath>..\..\build\obj\$(Platform)\$(Configuration)\otTestRunner\</BaseIntermediateOutputPath>
<OutputPath>..\..\build\bin\$(Platform)\$(Configuration)\exe\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\tests\otTestRunner\Program.cs" />
<Compile Include="..\..\tests\otTestRunner\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\tests\otTestRunner\App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
+372
View File
@@ -0,0 +1,372 @@
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* @brief
* This file defines a node interface for openthread.h to be used for certification tests
*/
#ifndef OTNODE_H_
#define OTNODE_H_
#include <openthread.h>
#ifndef OTNODEAPI
#define OTNODEAPI __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
* Represents a virtual node for an openthread interface
*/
typedef struct otNode otNode;
/**
* Logs a WPP message
*/
OTNODEAPI int32_t OTCALL otNodeLog(const char *aMessage);
/**
* Allocates a new virtual node
*/
OTNODEAPI otNode* OTCALL otNodeInit(uint32_t id);
/**
* Frees a node
*/
OTNODEAPI int32_t OTCALL otNodeFinalize(otNode* aNode);
/**
* Sets the link mode
*/
OTNODEAPI int32_t OTCALL otNodeSetMode(otNode* aNode, const char *aMode);
/**
* Starts the thread interface
*/
OTNODEAPI int32_t OTCALL otNodeInterfaceUp(otNode* aNode);
/**
* Stops the thread interface
*/
OTNODEAPI int32_t OTCALL otNodeInterfaceDown(otNode* aNode);
/**
* Starts the thread logic
*/
OTNODEAPI int32_t OTCALL otNodeThreadStart(otNode* aNode);
/**
* Stops the thread logic
*/
OTNODEAPI int32_t OTCALL otNodeThreadStop(otNode* aNode);
/**
* Starts the commissioner logic
*/
OTNODEAPI int32_t OTCALL otNodeCommissionerStart(otNode* aNode);
/**
* Adds a new joiner to the list for commissioning
*/
OTNODEAPI int32_t OTCALL otNodeCommissionerJoinerAdd(otNode* aNode, const char *aExtAddr, const char *aPSKd);
/**
* Stops the commissioner logic
*/
OTNODEAPI int32_t OTCALL otNodeCommissionerStop(otNode* aNode);
/**
* Starts the joiner logic
*/
OTNODEAPI int32_t OTCALL otNodeJoinerStart(otNode* aNode, const char *aPSKd, const char *aProvisioningUrl);
/**
* Clears the node's whitelist
*/
OTNODEAPI int32_t OTCALL otNodeClearWhitelist(otNode* aNode);
/**
* Enables the node's whitelist
*/
OTNODEAPI int32_t OTCALL otNodeEnableWhitelist(otNode* aNode);
/**
* Disables the node's whitelist
*/
OTNODEAPI int32_t OTCALL otNodeDisableWhitelist(otNode* aNode);
/**
* Adds an entry to the node's whitelist
*/
OTNODEAPI int32_t OTCALL otNodeAddWhitelist(otNode* aNode, const char *aExtAddr, int8_t aRssi);
/**
* Removes an entry to the node's whitelist
*/
OTNODEAPI int32_t OTCALL otNodeRemoveWhitelist(otNode* aNode, const char *aExtAddr);
/**
* Gets the node's short mac address (Rloc16)
*/
OTNODEAPI uint16_t OTCALL otNodeGetAddr16(otNode* aNode);
/**
* Gets the node's extended mac address
*/
OTNODEAPI const char* OTCALL otNodeGetAddr64(otNode* aNode);
/**
* Gets the node's hash mac address
*/
OTNODEAPI const char* OTCALL otNodeGetHashMacAddress(otNode* aNode);
/**
* Sets the channel for the node
*/
OTNODEAPI int32_t OTCALL otNodeSetChannel(otNode* aNode, uint8_t aChannel);
/**
* Gets the channel for the node
*/
OTNODEAPI uint8_t OTCALL otNodeGetChannel(otNode* aNode);
/**
* sets the node's master key
*/
OTNODEAPI int32_t OTCALL otNodeSetMasterkey(otNode* aNode, const char *aMasterkey);
/**
* Gets the node's master key
*/
OTNODEAPI const char* OTCALL otNodeGetMasterkey(otNode* aNode);
/**
* Gets the key sequence counter for the node
*/
OTNODEAPI uint32_t OTCALL otNodeGetKeySequenceCounter(otNode* aNode);
/**
* Sets the key sequence counter for the node
*/
OTNODEAPI int32_t OTCALL otNodeSetKeySequenceCounter(otNode* aNode, uint32_t aSequence);
/**
* Sets the key switch guard time for the node
*/
OTNODEAPI int32_t OTCALL otNodeSetKeySwitchGuardTime(otNode* aNode, uint32_t aSequence);
/**
* Sets the network id timeout for the node
*/
OTNODEAPI int32_t OTCALL otNodeSetNetworkIdTimeout(otNode* aNode, uint8_t aTimeout);
/**
* Gets the network name for the node
*/
OTNODEAPI const char* OTCALL otNodeGetNetworkName(otNode* aNode);
/**
* Sets the network name for the node
*/
OTNODEAPI int32_t OTCALL otNodeSetNetworkName(otNode* aNode, const char *aName);
/**
* Gets the pan id for the node
*/
OTNODEAPI uint16_t OTCALL otNodeGetPanId(otNode* aNode);
/**
* Sets the pan id for the node
*/
OTNODEAPI int32_t OTCALL otNodeSetPanId(otNode* aNode, uint16_t aPanId);
/**
* Gets the partition id for the node
*/
OTNODEAPI uint32_t OTCALL otNodeGetPartitionId(otNode* aNode);
/**
* Sets the partition id for the node
*/
OTNODEAPI int32_t OTCALL otNodeSetPartitionId(otNode* aNode, uint32_t aPartitionId);
/**
* Sets the router upgrade threshold for the node
*/
OTNODEAPI int32_t OTCALL otNodeSetRouterUpgradeThreshold(otNode* aNode, uint8_t aThreshold);
/**
* Sets the router downgrade threshold for the node
*/
OTNODEAPI int32_t OTCALL otNodeSetRouterDowngradeThreshold(otNode* aNode, uint8_t aThreshold);
/**
* Releases a router id for the node
*/
OTNODEAPI int32_t OTCALL otNodeReleaseRouterId(otNode* aNode, uint8_t aRouterId);
/**
* Gets the node's state
*/
OTNODEAPI const char* OTCALL otNodeGetState(otNode* aNode);
/**
* Sets the node's state
*/
OTNODEAPI int32_t OTCALL otNodeSetState(otNode* aNode, const char *aState);
/**
* Gets the child timeout for the node
*/
OTNODEAPI uint32_t OTCALL otNodeGetTimeout(otNode* aNode);
/**
* Sets the child timeout for the node
*/
OTNODEAPI int32_t OTCALL otNodeSetTimeout(otNode* aNode, uint32_t aTimeout);
/**
* Gets the leader weight for the node
*/
OTNODEAPI uint8_t OTCALL otNodeGetWeight(otNode* aNode);
/**
* Sets the leader weight for the node
*/
OTNODEAPI int32_t OTCALL otNodeSetWeight(otNode* aNode, uint8_t aWeight);
/**
* Adds an IP address for the node
*/
OTNODEAPI int32_t OTCALL otNodeAddIpAddr(otNode* aNode, const char *aAddr);
/**
* Gets the IP address for the node
*/
OTNODEAPI const char* OTCALL otNodeGetAddrs(otNode* aNode);
/**
* Gets the context reuse delay for the node
*/
OTNODEAPI uint32_t OTCALL otNodeGetContextReuseDelay(otNode* aNode);
/**
* Sets the context reuse delay for the node
*/
OTNODEAPI int32_t OTCALL otNodeSetContextReuseDelay(otNode* aNode, uint32_t aDelay);
/**
* Adds an IP prefix for the node
*/
OTNODEAPI int32_t OTCALL otNodeAddPrefix(otNode* aNode, const char *aPrefix, const char *aFlags, const char *aPreference);
/**
* Removes an IP prefix from the node
*/
OTNODEAPI int32_t OTCALL otNodeRemovePrefix(otNode* aNode, const char *aPrefix);
/**
* Adds an IP route for the node
*/
OTNODEAPI int32_t OTCALL otNodeAddRoute(otNode* aNode, const char *aPrefix, const char *aPreference);
/**
* Removes an IP route from the node
*/
OTNODEAPI int32_t OTCALL otNodeRemoveRoute(otNode* aNode, const char *aPrefix);
/**
* Registers the net data for the node
*/
OTNODEAPI int32_t OTCALL otNodeRegisterNetdata(otNode* aNode);
/**
* Performs an energy scan for the node
*/
OTNODEAPI int32_t OTCALL otNodeEnergyScan(otNode* aNode, uint32_t aMask, uint8_t aCount, uint16_t aPeriod, uint16_t aDuration, const char *aAddr);
/**
* Performs a panid query for the node
*/
OTNODEAPI int32_t OTCALL otNodePanIdQuery(otNode* aNode, uint16_t aPanId, uint32_t aMask, const char *aAddr);
/**
* Performs an scan for the node
*/
OTNODEAPI const char* OTCALL otNodeScan(otNode* aNode);
/**
* Performs an scan for the node
*/
OTNODEAPI uint32_t OTCALL otNodePing(otNode* aNode, const char *aAddr, uint16_t aSize, uint32_t aMinReplies);
/**
* Sets the router selection jitter value for a node
*/
OTNODEAPI int32_t OTCALL otNodeSetRouterSelectionJitter(otNode* aNode, uint8_t aRouterJitter);
/**
* Sends the announce message for a node
*/
OTNODEAPI int32_t OTCALL otNodeCommissionerAnnounceBegin(otNode* aNode, uint32_t aChannelMask, uint8_t aCount, uint16_t aPeriod, const char *aAddr);
/**
* Sets the active dataset for a node
*/
OTNODEAPI int32_t OTCALL otNodeSetActiveDataset(otNode* aNode, uint64_t aTimestamp, uint16_t aPanId, uint16_t aChannel, uint32_t aChannelMask, const char *aMasterKey);
/**
* Sets the pending dataset for a node
*/
OTNODEAPI int32_t OTCALL otNodeSetPendingDataset(otNode* aNode, uint64_t aActiveTimestamp, uint64_t aPendingTimestamp, uint16_t aPanId, uint16_t aChannel);
/**
* Sends a pending set for a node
*/
OTNODEAPI int32_t OTCALL otNodeSendPendingSet(otNode* aNode, uint64_t aActiveTimestamp, uint64_t aPendingTimestamp, uint32_t aDelayTimer, uint16_t aPanId, uint16_t aChannel, const char *aMasterKey, const char *aMeshLocal, const char *aNetworkName);
/**
* Sends a active set for a node
*/
OTNODEAPI int32_t OTCALL otNodeSendActiveSet(otNode* aNode, uint64_t aActiveTimestamp, uint16_t aPanId, uint16_t aChannel, uint32_t aChannelMask, const char *aExtPanId, const char *aMasterKey, const char *aMeshLocal, const char *aNetworkName, const char *aBinary);
/**
* Sets the maximum number of children for a node
*/
OTNODEAPI int32_t OTCALL otNodeSetMaxChildren(otNode* aNode, uint8_t aMaxChildren);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // OTNODE_H_
+11
View File
@@ -2837,6 +2837,17 @@ otPlatformReset(
if (aInstance) (void)SetIOCTL(aInstance, IOCTL_OTLWF_OT_PLATFORM_RESET);
}
OTAPI
void
OTCALL
otFactoryReset(
_In_ otInstance *aInstance
)
{
UNREFERENCED_PARAMETER(aInstance);
// TODO ...
}
OTAPI
ThreadError
OTCALL
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "precomp.h"
#include "dllmain.tmh"
BOOL
__stdcall
DllMain(
HINSTANCE hinstDll,
DWORD dwReason,
LPVOID /* lpvReserved */
)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hinstDll);
WPP_INIT_TRACING(L"otNodeApi");
break;
case DLL_PROCESS_DETACH:
Unload();
WPP_CLEANUP();
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <winnt.h>
#include <winsock2.h>
#include <ws2ipdef.h>
#include <IPHlpApi.h>
#include <mstcpip.h>
#include <rpc.h>
#include <rpcdce.h>
#include <assert.h>
#include <new>
#include <vector>
#include <tuple>
using namespace std;
// Define to export necessary functions
#define OTDLL
#define OTNODEAPI EXTERN_C __declspec(dllexport)
#include <openthread.h>
#include <commissioning/commissioner.h>
#include <commissioning/joiner.h>
#include <platform/logging-windows.h>
#include <otNode.h>
void Unload();
+129
View File
@@ -138,6 +138,135 @@ ThreadError otSetLinkPromiscuous(otInstance *aInstance, bool aPromiscuous);
*
*/
/**
* Get the list of IPv6 multicast addresses subscribed to the Thread interface.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @returns A pointer to the first Network Interface Multicast Address.
*/
const otNetifMulticastAddress *otGetMulticastAddresses(otInstance *aInstance);
/**
* Subscribe the Thread interface to a Network Interface Multicast Address.
*
* The passed in instance @p aAddress will be copied by the Thread interface. The Thread interface only
* supports a fixed number of externally added multicast addresses. See OPENTHREAD_CONFIG_MAX_EXT_MULTICAST_IP_ADDRS.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aAddress A pointer to an IP Address.
*
* @retval kThreadErrorNone Successfully subscribed to the Network Interface Multicast Address.
* @retval kThreadError_InvalidArgs The IP Address indicated by @p aAddress is invalid address.
* @retval kThreadError_NoBufs The Network Interface is already storing the maximum allowed external multicast addresses.
*/
ThreadError otSubscribeMulticastAddress(otInstance *aInstance, const otIp6Address *aAddress);
/**
* Unsubscribe the Thread interface to a Network Interface Multicast Address.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aAddress A pointer to an IP Address.
*
* @retval kThreadErrorNone Successfully unsubscribed to the Network Interface Multicast Address.
* @retval kThreadError_InvalidArgs The IP Address indicated by @p aAddress is an internal address.
* @retval kThreadError_NotFound The IP Address indicated by @p aAddress was not found.
*/
ThreadError otUnsubscribeMulticastAddress(otInstance *aInstance, const otIp6Address *aAddress);
/**
* Check if multicast promiscuous mode is enabled on the Thread interface.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @sa otEnableMulticastPromiscuousMode
* @sa otDisableMulticastPromiscuousMode
*/
bool otIsMulticastPromiscuousModeEnabled(otInstance *aInstance);
/**
* Enable multicast promiscuous mode on the Thread interface.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @sa otIsMulticastPromiscuousModeEnabled
* @sa otDisableMulticastPromiscuousMode
*/
void otEnableMulticastPromiscuousMode(otInstance *aInstance);
/**
* Disable multicast promiscuous mode on the Thread interface.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @sa otIsMulticastPromiscuousModeEnabled
* @sa otEnableMulticastPromiscuousMode
*/
void otDisableMulticastPromiscuousMode(otInstance *aInstance);
/**
* This function pointer is called to create IPv6 IID during SLAAC procedure.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[inout] aAddress A pointer to structure containing IPv6 address for which IID is being created.
* @param[inout] aContext A pointer to creator-specific context.
*
* @retval kThreadError_None Created valid IID for given IPv6 address.
* @retval kThreadError_Ipv6AddressCreationFailure Creation of valid IID for given IPv6 address failed.
*
*/
typedef ThreadError(*otSlaacIidCreate)(otInstance *aInstance, otNetifAddress *aAddress, void *aContext);
/**
* Update all automatically created IPv6 addresses for prefixes from current Network Data with SLAAC procedure.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[inout] aAddresses A pointer to an array of automatically created IPv6 addresses.
* @param[in] aNumAddresses The number of slots in aAddresses array.
* @param[in] aIidCreate A pointer to a function that is called to create IPv6 IIDs.
* @param[in] aContext A pointer to data passed to aIidCreate function.
*
*/
void otSlaacUpdate(otInstance *aInstance, otNetifAddress *aAddresses, uint32_t aNumAddresses,
otSlaacIidCreate aIidCreate, void *aContext);
/**
* Create random IID for given IPv6 address.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[inout] aAddress A pointer to structure containing IPv6 address for which IID is being created.
* @param[in] aContext A pointer to unused data.
*
* @retval kThreadError_None Created valid IID for given IPv6 address.
*
*/
ThreadError otCreateRandomIid(otInstance *aInstance, otNetifAddress *aAddresses, void *aContext);
/**
* Create IID for given IPv6 address using extended MAC address.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[inout] aAddress A pointer to structure containing IPv6 address for which IID is being created.
* @param[in] aContext A pointer to unused data.
*
* @retval kThreadError_None Created valid IID for given IPv6 address.
*
*/
ThreadError otCreateMacIid(otInstance *aInstance, otNetifAddress *aAddresses, void *aContext);
/**
* Create semantically opaque IID for given IPv6 address.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[inout] aAddress A pointer to structure containing IPv6 address for which IID is being created.
* @param[inout] aContext A pointer to a otSemanticallyOpaqueIidGeneratorData structure.
*
* @retval kThreadError_None Created valid IID for given IPv6 address.
* @retval kThreadError_Ipv6AddressCreationFailure Could not create valid IID for given IPv6 address.
*
*/
ThreadError otCreateSemanticallyOpaqueIid(otInstance *aInstance, otNetifAddress *aAddresses, void *aContext);
/**
* Allocate a new message buffer for sending an IPv6 message.
*
+1 -130
View File
@@ -858,135 +858,6 @@ OTAPI ThreadError OTCALL otAddUnicastAddress(otInstance *aInstance, const otNeti
*/
OTAPI ThreadError OTCALL otRemoveUnicastAddress(otInstance *aInstance, const otIp6Address *aAddress);
/**
* Get the list of IPv6 multicast addresses subscribed to the Thread interface.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @returns A pointer to the first Network Interface Multicast Address.
*/
const otNetifMulticastAddress *otGetMulticastAddresses(otInstance *aInstance);
/**
* Subscribe the Thread interface to a Network Interface Multicast Address.
*
* The passed in instance @p aAddress will be copied by the Thread interface. The Thread interface only
* supports a fixed number of externally added multicast addresses. See OPENTHREAD_CONFIG_MAX_EXT_MULTICAST_IP_ADDRS.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aAddress A pointer to an IP Address.
*
* @retval kThreadErrorNone Successfully subscribed to the Network Interface Multicast Address.
* @retval kThreadError_InvalidArgs The IP Address indicated by @p aAddress is invalid address.
* @retval kThreadError_NoBufs The Network Interface is already storing the maximum allowed external multicast addresses.
*/
ThreadError otSubscribeMulticastAddress(otInstance *aInstance, const otIp6Address *aAddress);
/**
* Unsubscribe the Thread interface to a Network Interface Multicast Address.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aAddress A pointer to an IP Address.
*
* @retval kThreadErrorNone Successfully unsubscribed to the Network Interface Multicast Address.
* @retval kThreadError_InvalidArgs The IP Address indicated by @p aAddress is an internal address.
* @retval kThreadError_NotFound The IP Address indicated by @p aAddress was not found.
*/
ThreadError otUnsubscribeMulticastAddress(otInstance *aInstance, const otIp6Address *aAddress);
/**
* Check if multicast promiscuous mode is enabled on the Thread interface.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @sa otEnableMulticastPromiscuousMode
* @sa otDisableMulticastPromiscuousMode
*/
bool otIsMulticastPromiscuousModeEnabled(otInstance *aInstance);
/**
* Enable multicast promiscuous mode on the Thread interface.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @sa otIsMulticastPromiscuousModeEnabled
* @sa otDisableMulticastPromiscuousMode
*/
void otEnableMulticastPromiscuousMode(otInstance *aInstance);
/**
* Disable multicast promiscuous mode on the Thread interface.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @sa otIsMulticastPromiscuousModeEnabled
* @sa otEnableMulticastPromiscuousMode
*/
void otDisableMulticastPromiscuousMode(otInstance *aInstance);
/**
* This function pointer is called to create IPv6 IID during SLAAC procedure.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[inout] aAddress A pointer to structure containing IPv6 address for which IID is being created.
* @param[inout] aContext A pointer to creator-specific context.
*
* @retval kThreadError_None Created valid IID for given IPv6 address.
* @retval kThreadError_Ipv6AddressCreationFailure Creation of valid IID for given IPv6 address failed.
*
*/
typedef ThreadError(*otSlaacIidCreate)(otInstance *aInstance, otNetifAddress *aAddress, void *aContext);
/**
* Update all automatically created IPv6 addresses for prefixes from current Network Data with SLAAC procedure.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[inout] aAddresses A pointer to an array of automatically created IPv6 addresses.
* @param[in] aNumAddresses The number of slots in aAddresses array.
* @param[in] aIidCreate A pointer to a function that is called to create IPv6 IIDs.
* @param[in] aContext A pointer to data passed to aIidCreate function.
*
*/
void otSlaacUpdate(otInstance *aInstance, otNetifAddress *aAddresses, uint32_t aNumAddresses,
otSlaacIidCreate aIidCreate, void *aContext);
/**
* Create random IID for given IPv6 address.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[inout] aAddress A pointer to structure containing IPv6 address for which IID is being created.
* @param[in] aContext A pointer to unused data.
*
* @retval kThreadError_None Created valid IID for given IPv6 address.
*
*/
ThreadError otCreateRandomIid(otInstance *aInstance, otNetifAddress *aAddresses, void *aContext);
/**
* Create IID for given IPv6 address using extended MAC address.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[inout] aAddress A pointer to structure containing IPv6 address for which IID is being created.
* @param[in] aContext A pointer to unused data.
*
* @retval kThreadError_None Created valid IID for given IPv6 address.
*
*/
ThreadError otCreateMacIid(otInstance *aInstance, otNetifAddress *aAddresses, void *aContext);
/**
* Create semantically opaque IID for given IPv6 address.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[inout] aAddress A pointer to structure containing IPv6 address for which IID is being created.
* @param[inout] aContext A pointer to a otSemanticallyOpaqueIidGeneratorData structure.
*
* @retval kThreadError_None Created valid IID for given IPv6 address.
* @retval kThreadError_Ipv6AddressCreationFailure Could not create valid IID for given IPv6 address.
*
*/
ThreadError otCreateSemanticallyOpaqueIid(otInstance *aInstance, otNetifAddress *aAddresses, void *aContext);
/**
* This function pointer is called to notify certain configuration or state changes within OpenThread.
*
@@ -1802,7 +1673,7 @@ OTAPI void OTCALL otPlatformReset(otInstance *aInstance);
*
* @param[in] aInstance A pointer to an OpenThread instance.
*/
void otFactoryReset(otInstance *aInstance);
OTAPI void OTCALL otFactoryReset(otInstance *aInstance);
/**
* Get the ROUTER_DOWNGRADE_THRESHOLD parameter used in the Router role.
+2 -2
View File
@@ -164,7 +164,7 @@ void Mpl::AddBufferedMessage(Message &aMessage, uint16_t aSeedId, uint8_t aSeque
Message *messageCopy = NULL;
MplBufferedMessageMetadata messageMetadata;
uint32_t nextTransmissionTime;
uint8_t hopLimit;
uint8_t hopLimit = 0;
VerifyOrExit(GetTimerExpirations() > 0,);
VerifyOrExit((messageCopy = aMessage.Clone()) != NULL, error = kThreadError_NoBufs);
@@ -172,7 +172,7 @@ void Mpl::AddBufferedMessage(Message &aMessage, uint16_t aSeedId, uint8_t aSeque
if (!aIsOutbound)
{
aMessage.Read(Header::GetHopLimitOffset(), Header::GetHopLimitSize(), &hopLimit);
VerifyOrExit(--hopLimit > 0, error = kThreadError_Drop);
VerifyOrExit(hopLimit-- > 1, error = kThreadError_Drop);
messageCopy->Write(Header::GetHopLimitOffset(), Header::GetHopLimitSize(), &hopLimit);
}
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
+64
View File
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("otTestRunner")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("otTestRunner")]
[assembly: AssemblyCopyright("Copyright © The OpenThread Authors 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("d5577e51-fa31-4802-8669-1db32805935e")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
+376
View File
@@ -0,0 +1,376 @@
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace otTestRunner
{
class Program
{
struct TestResults
{
public bool Pass;
public List<string> Output;
public string Error;
}
static string EscapeJson(string data)
{
return data.Replace("\\", "\\\\").Replace("\"", "\\\"");
}
/// <summary>
/// Executes an exe with the given args and captures the output
/// </summary>
static async Task<TestResults> ExecuteAsync(string name, string args = null, int timeoutMilliseconds = -1, int instanceIndex = -1)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardOutput = true;
startInfo.FileName = name;
startInfo.Arguments = args;
startInfo.EnvironmentVariables["NODE_TYPE"] = "win-sim";
if (instanceIndex != -1)
{
startInfo.EnvironmentVariables["INSTANCE"] = instanceIndex.ToString();
}
TestResults Results = new TestResults();
Results.Pass = false;
Results.Output = new List<string>();
Results.Error = null;
var Errors = new List<string>();
Results.Output.Add(string.Format("> set NODE_TYPE=win-sim"));
Results.Output.Add(string.Format("> {0} {1}", name, args));
Results.Output.Add("----------------------------------------------------------------------");
try
{
// Execute process
using (Process process = Process.Start(startInfo))
{
process.OutputDataReceived +=
(object sender, DataReceivedEventArgs e) => {
if (e.Data != null && e.Data.Length > 0)
lock (Results.Output) { Results.Output.Add(e.Data); }
};
process.ErrorDataReceived +=
(object sender, DataReceivedEventArgs e) => {
if (e.Data != null && e.Data.Length > 0)
lock (Results.Output) { Errors.Add(e.Data); }
};
process.BeginErrorReadLine();
process.BeginOutputReadLine();
#if DEBUG
Console.WriteLine("Starting {0} {1}", name, args);
#endif
// Wait for process to complete
await Task.Run(
() => {
if (timeoutMilliseconds == -1)
process.WaitForExit();
else if (!process.WaitForExit(timeoutMilliseconds))
{
process.Kill();
Results.Output.Add(string.Format("Killed {0} on execution timeout!", name));
}
});
// Wait a bit for any output to collect
await Task.Delay(1000);
process.CancelOutputRead();
process.CancelErrorRead();
Results.Output.AddRange(Errors);
Results.Pass = Errors.Count > 0 && Errors[Errors.Count - 1] == "OK";
if (!Results.Pass) Results.Error = EscapeJson(string.Join("\\r\\n", Errors));
// Make sure the process is killed
try { process.Kill(); } catch (Exception) { }
#if DEBUG
Console.WriteLine("Completed {0} {1}", name, args);
#endif
}
}
catch (Exception e)
{
Results.Output.Add("Encountered exception: " + e.Message);
Results.Output.Add(e.StackTrace);
}
return Results;
}
static bool VerboseOutput = false;
static int RetiresOnFailure = 0;
static bool AppVeyorMode = false;
static string AppVeyorApiUrl = null;
static string ResultsFolder = "Results_" + DateTime.Now.ToString("yyyyMMdd_HH.mm.ss");
static void UploadAppVeyorTestResult(string name, bool passed, long durationMS, string error = null)
{
if (AppVeyorApiUrl == null) return;
string jsonData = null;
try
{
var request = (HttpWebRequest)WebRequest.Create(Path.Combine(AppVeyorApiUrl, "api/tests"));
jsonData =
string.Format(
"{{" +
"\"testName\": \"{0}\", " +
"\"testFramework\": \"MSTest\", " +
"\"fileName\": \"{0}.py\", " +
"\"outcome\": \"{1}\", " +
"\"durationMilliseconds\": \"{2}\", " +
"\"ErrorMessage\": \"{3}\"" +
"}}",
name,
passed ? "Passed" : "Failed",
durationMS,
error == null ? "" : error
);
var data = Encoding.UTF8.GetBytes(jsonData);
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
}
catch (Exception e)
{
Console.WriteLine("Encountered exception for http post:");
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
Console.WriteLine("Json content:");
Console.WriteLine(jsonData);
}
}
/// <summary>
/// Runs a python test file and returns success/failure
/// </summary>
static async Task<bool> RunTest(string file, int index)
{
string pythonPath = "python.exe";
if (AppVeyorMode)
{
if (Environment.GetEnvironmentVariable("Platform").ToLower() == "x64")
{
pythonPath = @"c:\python35-x64\python.exe";
}
else
{
pythonPath = @"c:\python35\python.exe";
}
}
int tries = 0;
Stopwatch Timer;
TestResults Results;
do
{
Timer = new Stopwatch();
Timer.Start();
Results = await ExecuteAsync(pythonPath, file, 30 * 60 * 1000, index);
Timer.Stop();
} while (++tries < RetiresOnFailure + 1 && Results.Pass == false);
if (VerboseOutput)
{
lock (ResultsFolder)
{
foreach (var line in Results.Output)
Console.WriteLine(line);
}
}
UploadAppVeyorTestResult(Path.GetFileNameWithoutExtension(file), Results.Pass, Timer.ElapsedMilliseconds, Results.Error);
// Write the output to a file
var filePrefix = Results.Pass ? "P_" : "F_";
var outputFilePath = Path.Combine(ResultsFolder, filePrefix + Path.GetFileNameWithoutExtension(file) + ".txt");
try {
File.WriteAllLines(outputFilePath, Results.Output);
} catch (Exception e) {
Console.WriteLine("Exception while trying to write {0}:\n{1}!", outputFilePath, e.Message);
}
return Results.Pass;
}
/// <summary>
/// Runs all the tests as indicated by input arguments
/// </summary>
static void Main(string[] args)
{
if (args.Length < 2)
{
Console.WriteLine("Usage: otTestRunner.exe [path] [search pattern] (parallel:n) (verbose)");
return;
}
var files = Directory.GetFiles(args[0], args[1]);
if (files.Length == 0)
{
Console.WriteLine("No tests found with that path & pattern!");
return;
}
var NumberOfTestsToRunInParallel = 1;
for (var i = 2; i < args.Length; i++)
{
if (args[i].StartsWith("parallel:"))
NumberOfTestsToRunInParallel = int.Parse(args[i].Substring(9));
else if (args[i].StartsWith("retry:"))
RetiresOnFailure = int.Parse(args[i].Substring(6));
else if (args[i].StartsWith("verbose"))
VerboseOutput = true;
else if (args[i].StartsWith("appveyor"))
{
AppVeyorMode = true;
AppVeyorApiUrl = Environment.GetEnvironmentVariable("APPVEYOR_API_URL");
//Console.WriteLine("AppVeyorApiUrl = {0}", AppVeyorApiUrl);
}
}
var CurNumTestsRunning = 0;
var ReadyToRunEvent = new ManualResetEvent(true);
var TestPassCount = 0;
Stopwatch Timer = new Stopwatch();
Directory.CreateDirectory(ResultsFolder);
Console.WriteLine("Test results saved: .\\{0}", ResultsFolder);
Console.WriteLine("Running {0} tests, {1} at a time:", files.Length, NumberOfTestsToRunInParallel);
/*for (var i = 0; i < files.Length; i++)
Console.WriteLine(Path.GetFileName(files[i]));*/
Console.WriteLine("");
Timer.Start();
for (var i = 0; i < files.Length; i++)
{
// Wait for the event to be set, if not already
ReadyToRunEvent.WaitOne();
if (i != 0)
{
// Wait a bit to stagger the starts
Task.Delay(1000).Wait();
}
lock (ResultsFolder)
{
if (++CurNumTestsRunning == NumberOfTestsToRunInParallel)
ReadyToRunEvent.Reset();
}
var index = i;
var fileName = files[i];
// Start the test, but don't wait for it
Task.Run(
async () =>
{
var result = await RunTest(fileName, index);
lock (ResultsFolder)
{
var PrevColor = Console.ForegroundColor;
if (result)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("PASS");
TestPassCount++;
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("FAIL");
}
Console.ForegroundColor = PrevColor;
Console.WriteLine(": {0}", Path.GetFileNameWithoutExtension(fileName));
CurNumTestsRunning--;
ReadyToRunEvent.Set();
}
});
}
// Wait for all the tests to complete
while (CurNumTestsRunning != 0)
ReadyToRunEvent.WaitOne();
Timer.Stop();
TimeSpan ts = Timer.Elapsed;
string elapsedTime =
String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
Console.WriteLine("{0} tests run in {1}", files.Length, elapsedTime);
Console.WriteLine("{0} passed and {1} failed", TestPassCount, files.Length - TestPassCount);
if (!AppVeyorMode)
Environment.ExitCode = files.Length == TestPassCount ? 0 : 1;
}
}
}
+1
View File
@@ -131,6 +131,7 @@ EXTRA_DIST = \
thread-cert/net_crypto.py \
thread-cert/network_data.py \
thread-cert/node.py \
thread-cert/node_cli.py \
thread-cert/sniffer.py \
$(NULL)
+77
View File
@@ -0,0 +1,77 @@
#!/usr/bin/python
#
# Copyright (c) 2016, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
import unittest
import ctypes
class GUID(ctypes.Structure):
_fields_ = [("Data1", ctypes.c_uint),
("Data2", ctypes.c_ushort),
("Data3", ctypes.c_ushort),
("Data4", ctypes.c_ubyte * 8)]
class otDeviceList(ctypes.Structure):
_fields_ = [("aDevicesLength", ctypes.c_ushort),
("aDevices", GUID * 64)]
class Cert_otLwf(unittest.TestCase):
def setUp(self):
# Load the DLL
self.Api = ctypes.WinDLL("otApi.dll")
if self.Api == None:
raise OSError("Failed to load otApi.dll!")
# Define the functions
self.Api.otApiInit.restype = ctypes.c_void_p
self.Api.otApiFinalize.argtypes = [ctypes.c_void_p]
self.Api.otApiFinalize.restype = None
self.Api.otFreeMemory.argtypes = [ctypes.c_void_p]
self.Api.otFreeMemory.restype = None
self.Api.otEnumerateDevices.argtypes = [ctypes.c_void_p]
self.Api.otEnumerateDevices.restype = ctypes.POINTER(otDeviceList)
def tearDown(self):
if self.ApiInstance:
self.Api.otApiFinalize(self.ApiInstance)
def test(self):
# Instantiate the API
self.ApiInstance = self.Api.otApiInit()
# Assert that it didn't return NULL
self.assertNotEqual(self.ApiInstance, None)
# Query the device list
devices = self.Api.otEnumerateDevices(self.ApiInstance)
# Assert that it didn't return NULL
self.assertNotEqual(devices, None)
# Print the number of devices
print("devices found: %d" % devices.contents.aDevicesLength)
if __name__ == '__main__':
unittest.main()
+79 -430
View File
@@ -30,568 +30,217 @@
import os
import sys
import time
import pexpect
if sys.platform != 'win32':
import node_cli
else:
import node_api
import unittest
class Node:
def __init__(self, nodeid):
self.nodeid = nodeid
self.verbose = int(float(os.getenv('VERBOSE', 0)))
self.node_type = os.getenv('NODE_TYPE', 'sim')
if self.node_type == 'soc':
self.__init_soc(nodeid)
elif self.node_type == 'ncp-sim':
self.__init_ncp_sim(nodeid)
if sys.platform != 'win32':
self.interface = node_cli.otCli(nodeid)
else:
self.__init_sim(nodeid)
self.interface = node_api.otApi(nodeid)
if self.verbose:
self.pexpect.logfile_read = sys.stdout
self.clear_whitelist()
self.disable_whitelist()
self.set_timeout(100)
def __init_sim(self, nodeid):
""" Initialize a simulation node. """
if "OT_CLI_PATH" in os.environ.keys():
cmd = os.environ['OT_CLI_PATH']
elif "top_builddir" in os.environ.keys():
srcdir = os.environ['top_builddir']
cmd = '%s/examples/apps/cli/ot-cli-ftd' % srcdir
else:
cmd = './ot-cli-ftd'
cmd += ' %d' % nodeid
print ("%s" % cmd)
self.pexpect = pexpect.spawn(cmd, timeout=4)
# Add delay to ensure that the process is ready to receive commands.
time.sleep(0.2)
def __init_ncp_sim(self, nodeid):
""" Initialize an NCP simulation node. """
if "top_builddir" in os.environ.keys():
builddir = os.environ['top_builddir']
if "top_srcdir" in os.environ.keys():
srcdir = os.environ['top_srcdir']
else:
srcdir = os.path.dirname(os.path.realpath(__file__))
srcdir += "/../../.."
cmd = 'python %s/tools/spinel-cli/spinel-cli.py -p %s/examples/apps/ncp/ot-ncp -n' % (srcdir, builddir)
else:
cmd = './ot-ncp'
cmd += ' %d' % nodeid
print ("%s" % cmd)
self.pexpect = pexpect.spawn(cmd, timeout=4)
time.sleep(0.2)
self.pexpect.expect('spinel-cli >')
self.debug(int(os.getenv('DEBUG', '0')))
def __init_soc(self, nodeid):
""" Initialize a System-on-a-chip node connected via UART. """
import fdpexpect
serialPort = '/dev/ttyUSB%d' % ((nodeid-1)*2)
self.pexpect = fdpexpect.fdspawn(os.open(serialPort, os.O_RDWR|os.O_NONBLOCK|os.O_NOCTTY))
self.interface.clear_whitelist()
self.interface.disable_whitelist()
self.interface.set_timeout(100)
def __del__(self):
if self.pexpect.isalive():
self.send_command('exit')
self.pexpect.expect(pexpect.EOF)
self.pexpect.terminate()
self.pexpect.close(force=True)
del self.interface
def send_command(self, cmd):
print ("%d: %s" % (self.nodeid, cmd))
self.pexpect.sendline(cmd)
def get_commands(self):
self.send_command('?')
self.pexpect.expect('Commands:')
commands = []
while True:
i = self.pexpect.expect(['Done', '(\S+)'])
if i != 0:
commands.append(self.pexpect.match.groups()[0])
else:
break
return commands
def set_mode(self, mode):
cmd = 'mode ' + mode
self.send_command(cmd)
self.pexpect.expect('Done')
def set_mode(self, mode):
self.interface.set_mode(mode)
def debug(self, level):
self.send_command('debug '+str(level))
self.interface.debug(level)
def interface_up(self):
self.send_command('ifconfig up')
self.pexpect.expect('Done')
self.interface.interface_up()
def interface_down(self):
self.send_command('ifconfig down')
self.pexpect.expect('Done')
self.interface.interface_down()
def thread_start(self):
self.send_command('thread start')
self.pexpect.expect('Done')
self.interface.thread_start()
def thread_stop(self):
self.send_command('thread stop')
self.pexpect.expect('Done')
self.interface.thread_stop()
def commissioner_start(self):
cmd = 'commissioner start'
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.commissioner_start()
def commissioner_add_joiner(self, addr, psk):
cmd = 'commissioner joiner add ' + addr + ' ' + psk
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.commissioner_add_joiner(addr, psk)
def joiner_start(self, pskd='', provisioning_url=''):
cmd = 'joiner start ' + pskd + ' ' + provisioning_url
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.joiner_start(pskd, provisioning_url)
def start(self):
self.interface_up()
self.thread_start()
self.interface.interface_up()
self.interface.thread_start()
def stop(self):
self.thread_stop()
self.interface_down()
self.interface.thread_stop()
self.interface.interface_down()
def clear_whitelist(self):
self.send_command('whitelist clear')
self.pexpect.expect('Done')
self.interface.clear_whitelist()
def enable_whitelist(self):
self.send_command('whitelist enable')
self.pexpect.expect('Done')
self.interface.enable_whitelist()
def disable_whitelist(self):
self.send_command('whitelist disable')
self.pexpect.expect('Done')
self.interface.disable_whitelist()
def add_whitelist(self, addr, rssi=None):
cmd = 'whitelist add ' + addr
if rssi != None:
cmd += ' ' + str(rssi)
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.add_whitelist(addr, rssi)
def remove_whitelist(self, addr):
cmd = 'whitelist remove ' + addr
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.remove_whitelist(addr)
def get_addr16(self):
self.send_command('rloc16')
i = self.pexpect.expect('([0-9a-fA-F]{4})')
if i == 0:
addr16 = int(self.pexpect.match.groups()[0], 16)
self.pexpect.expect('Done')
return addr16
return self.interface.get_addr16()
def get_addr64(self):
self.send_command('extaddr')
i = self.pexpect.expect('([0-9a-fA-F]{16})')
if i == 0:
addr64 = self.pexpect.match.groups()[0].decode("utf-8")
self.pexpect.expect('Done')
return addr64
return self.interface.get_addr64()
def get_hashmacaddr(self):
self.send_command('hashmacaddr')
i = self.pexpect.expect('([0-9a-fA-F]{16})')
if i == 0:
addr = self.pexpect.match.groups()[0].decode("utf-8")
self.pexpect.expect('Done')
return addr
return self.interface.get_hashmacaddr()
def get_channel(self):
self.send_command('channel')
i = self.pexpect.expect('(\d+)\r\n')
if i == 0:
channel = int(self.pexpect.match.groups()[0])
self.pexpect.expect('Done')
return channel
return self.interface.get_channel()
def set_channel(self, channel):
cmd = 'channel %d' % channel
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.set_channel(channel)
def get_masterkey(self):
self.send_command('masterkey')
i = self.pexpect.expect('([0-9a-fA-F]{32})')
if i == 0:
masterkey = self.pexpect.match.groups()[0].decode("utf-8")
self.pexpect.expect('Done')
return masterkey
return self.interface.get_masterkey()
def set_masterkey(self, masterkey):
cmd = 'masterkey ' + masterkey
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.set_masterkey(masterkey)
def get_key_sequence_counter(self):
self.send_command('keysequence counter')
i = self.pexpect.expect('(\d+)\r\n')
if i == 0:
key_sequence_counter = int(self.pexpect.match.groups()[0])
self.pexpect.expect('Done')
return key_sequence_counter
return self.interface.get_key_sequence_counter()
def set_key_sequence_counter(self, key_sequence_counter):
cmd = 'keysequence counter %d' % key_sequence_counter
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.set_key_sequence_counter(key_sequence_counter)
def set_key_switch_guardtime(self, key_switch_guardtime):
cmd = 'keysequence guardtime %d' % key_switch_guardtime
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.set_key_switch_guardtime(key_switch_guardtime)
def set_network_id_timeout(self, network_id_timeout):
cmd = 'networkidtimeout %d' % network_id_timeout
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.set_network_id_timeout(network_id_timeout)
def get_network_name(self):
self.send_command('networkname')
while True:
i = self.pexpect.expect(['Done', '(\S+)'])
if i != 0:
network_name = self.pexpect.match.groups()[0].decode('utf-8')
else:
break
return network_name
return self.interface.get_network_name()
def set_network_name(self, network_name):
cmd = 'networkname ' + network_name
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.set_network_name(network_name)
def get_panid(self):
self.send_command('panid')
i = self.pexpect.expect('([0-9a-fA-F]{4})')
if i == 0:
panid = int(self.pexpect.match.groups()[0], 16)
self.pexpect.expect('Done')
return panid
return self.interface.get_panid()
def set_panid(self, panid):
cmd = 'panid %d' % panid
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.set_panid(panid)
def get_partition_id(self):
self.send_command('leaderpartitionid')
i = self.pexpect.expect('(\d+)\r\n')
if i == 0:
weight = self.pexpect.match.groups()[0]
self.pexpect.expect('Done')
return weight
return self.interface.get_partition_id()
def set_partition_id(self, partition_id):
cmd = 'leaderpartitionid %d' % partition_id
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.set_partition_id(partition_id)
def set_router_upgrade_threshold(self, threshold):
cmd = 'routerupgradethreshold %d' % threshold
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.set_router_upgrade_threshold(threshold)
def set_router_downgrade_threshold(self, threshold):
cmd = 'routerdowngradethreshold %d' % threshold
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.set_router_downgrade_threshold(threshold)
def release_router_id(self, router_id):
cmd = 'releaserouterid %d' % router_id
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.release_router_id(router_id)
def get_state(self):
states = ['detached', 'child', 'router', 'leader']
self.send_command('state')
match = self.pexpect.expect(states)
self.pexpect.expect('Done')
return states[match]
return self.interface.get_state()
def set_state(self, state):
cmd = 'state ' + state
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.set_state(state)
def get_timeout(self):
self.send_command('childtimeout')
i = self.pexpect.expect('(\d+)\r\n')
if i == 0:
timeout = self.pexpect.match.groups()[0]
self.pexpect.expect('Done')
return timeout
return self.interface.get_timeout()
def set_timeout(self, timeout):
cmd = 'childtimeout %d' % timeout
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.set_timeout(timeout)
def set_max_children(self, number):
cmd = 'childmax %d' % number
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.set_max_children(number)
def get_weight(self):
self.send_command('leaderweight')
i = self.pexpect.expect('(\d+)\r\n')
if i == 0:
weight = self.pexpect.match.groups()[0]
self.pexpect.expect('Done')
return weight
return self.interface.get_weight()
def set_weight(self, weight):
cmd = 'leaderweight %d' % weight
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.set_weight(weight)
def add_ipaddr(self, ipaddr):
cmd = 'ipaddr add ' + ipaddr
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.add_ipaddr(ipaddr)
def get_addrs(self):
addrs = []
self.send_command('ipaddr')
while True:
i = self.pexpect.expect(['(\S+:\S+)\r\n', 'Done'])
if i == 0:
addrs.append(self.pexpect.match.groups()[0].decode("utf-8"))
elif i == 1:
break
return addrs
return self.interface.get_addrs()
def get_context_reuse_delay(self):
self.send_command('contextreusedelay')
i = self.pexpect.expect('(\d+)\r\n')
if i == 0:
timeout = self.pexpect.match.groups()[0]
self.pexpect.expect('Done')
return timeout
return self.interface.get_context_reuse_delay()
def set_context_reuse_delay(self, delay):
cmd = 'contextreusedelay %d' % delay
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.set_context_reuse_delay(delay)
def add_prefix(self, prefix, flags, prf = 'med'):
cmd = 'prefix add ' + prefix + ' ' + flags + ' ' + prf
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.add_prefix(prefix, flags, prf)
def remove_prefix(self, prefix):
cmd = ' prefix remove ' + prefix
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.remove_prefix(prefix)
def add_route(self, prefix, prf = 'med'):
cmd = 'route add ' + prefix + ' ' + prf
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.add_route(prefix, prf)
def remove_route(self, prefix):
cmd = 'route remove ' + prefix
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.remove_route(prefix)
def register_netdata(self):
self.send_command('netdataregister')
self.pexpect.expect('Done')
self.interface.register_netdata()
def energy_scan(self, mask, count, period, scan_duration, ipaddr):
cmd = 'commissioner energy ' + str(mask) + ' ' + str(count) + ' ' + str(period) + ' ' + str(scan_duration) + ' ' + ipaddr
self.send_command(cmd)
self.pexpect.expect('Energy:', timeout=8)
self.interface.energy_scan(mask, count, period, scan_duration, ipaddr)
def panid_query(self, panid, mask, ipaddr):
cmd = 'commissioner panid ' + str(panid) + ' ' + str(mask) + ' ' + ipaddr
self.send_command(cmd)
self.pexpect.expect('Conflict:', timeout=8)
self.interface.panid_query(panid, mask, ipaddr)
def scan(self):
self.send_command('scan')
results = []
while True:
i = self.pexpect.expect(['\|\s(\S+)\s+\|\s(\S+)\s+\|\s([0-9a-fA-F]{4})\s\|\s([0-9a-fA-F]{16})\s\|\s(\d+)\r\n',
'Done'])
if i == 0:
results.append(self.pexpect.match.groups())
else:
break
return results
return self.interface.scan()
def ping(self, ipaddr, num_responses=1, size=None):
cmd = 'ping ' + ipaddr
if size != None:
cmd += ' ' + str(size)
self.send_command(cmd)
result = True
try:
responders = {}
while len(responders) < num_responses:
i = self.pexpect.expect(['from (\S+):'])
if i == 0:
responders[self.pexpect.match.groups()[0]] = 1
self.pexpect.expect('\n')
except pexpect.TIMEOUT:
result = False
return result
return self.interface.ping(ipaddr, num_responses, size)
def set_router_selection_jitter(self, jitter):
cmd = 'routerselectionjitter %d' % jitter
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.set_router_selection_jitter(jitter)
def set_active_dataset(self, timestamp, panid=None, channel=None, channel_mask=None, master_key=None):
self.send_command('dataset clear')
self.pexpect.expect('Done')
cmd = 'dataset activetimestamp %d' % timestamp
self.send_command(cmd)
self.pexpect.expect('Done')
if panid != None:
cmd = 'dataset panid %d' % panid
self.send_command(cmd)
self.pexpect.expect('Done')
if channel != None:
cmd = 'dataset channel %d' % channel
self.send_command(cmd)
self.pexpect.expect('Done')
if channel_mask != None:
cmd = 'dataset channelmask %d' % channel_mask
self.send_command(cmd)
self.pexpect.expect('Done')
if master_key != None:
cmd = 'dataset masterkey ' + master_key
self.send_command(cmd)
self.pexpect.expect('Done')
self.send_command('dataset commit active')
self.pexpect.expect('Done')
self.interface.set_active_dataset(timestamp, panid, channel, channel_mask, master_key)
def set_pending_dataset(self, pendingtimestamp, activetimestamp, panid=None, channel=None):
self.send_command('dataset clear')
self.pexpect.expect('Done')
cmd = 'dataset pendingtimestamp %d' % pendingtimestamp
self.send_command(cmd)
self.pexpect.expect('Done')
cmd = 'dataset activetimestamp %d' % activetimestamp
self.send_command(cmd)
self.pexpect.expect('Done')
if panid != None:
cmd = 'dataset panid %d' % panid
self.send_command(cmd)
self.pexpect.expect('Done')
if channel != None:
cmd = 'dataset channel %d' % channel
self.send_command(cmd)
self.pexpect.expect('Done')
self.send_command('dataset commit pending')
self.pexpect.expect('Done')
self.interface.set_pending_dataset(pendingtimestamp, activetimestamp, panid, channel)
def announce_begin(self, mask, count, period, ipaddr):
cmd = 'commissioner announce ' + str(mask) + ' ' + str(count) + ' ' + str(period) + ' ' + ipaddr
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.announce_begin(mask, count, period, ipaddr)
def send_mgmt_active_set(self, active_timestamp=None, channel=None, channel_mask=None, extended_panid=None,
panid=None, master_key=None, mesh_local=None, network_name=None, binary=None):
cmd = 'dataset mgmtsetcommand active '
if active_timestamp != None:
cmd += 'activetimestamp %d ' % active_timestamp
if channel != None:
cmd += 'channel %d ' % channel
if channel_mask != None:
cmd += 'channelmask %d ' % channel_mask
if extended_panid != None:
cmd += 'extpanid ' + extended_panid + ' '
if panid != None:
cmd += 'panid %d ' % panid
if master_key != None:
cmd += 'masterkey ' + master_key + ' '
if mesh_local != None:
cmd += 'localprefix ' + mesh_local + ' '
if network_name != None:
cmd += 'networkname ' + network_name + ' '
if binary != None:
cmd += 'binary ' + binary + ' '
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.send_mgmt_active_set(active_timestamp, channel, channel_mask, extended_panid, panid,
master_key, mesh_local, network_name, binary)
def send_mgmt_pending_set(self, pending_timestamp=None, active_timestamp=None, delay_timer=None, channel=None,
panid=None, master_key=None, mesh_local=None, network_name=None):
cmd = 'dataset mgmtsetcommand pending '
if pending_timestamp != None:
cmd += 'pendingtimestamp %d ' % pending_timestamp
if active_timestamp != None:
cmd += 'activetimestamp %d ' % active_timestamp
if delay_timer != None:
cmd += 'delaytimer %d ' % delay_timer
if channel != None:
cmd += 'channel %d ' % channel
if panid != None:
cmd += 'panid %d ' % panid
if master_key != None:
cmd += 'masterkey ' + master_key + ' '
if mesh_local != None:
cmd += 'localprefix ' + mesh_local + ' '
if network_name != None:
cmd += 'networkname ' + network_name + ' '
self.send_command(cmd)
self.pexpect.expect('Done')
self.interface.send_mgmt_pending_set(pending_timestamp, active_timestamp, delay_timer, channel, panid,
master_key, mesh_local, network_name)
if __name__ == '__main__':
unittest.main()
+588
View File
@@ -0,0 +1,588 @@
#!/usr/bin/python
#
# Copyright (c) 2016, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
import os
import sys
import time
import ctypes
class otApi:
def __init__(self, nodeid):
self.verbose = int(float(os.getenv('VERBOSE', 0)))
self.__init_dll(nodeid)
def __del__(self):
self.Api.otNodeFinalize(self.otNode)
def set_mode(self, mode):
if self.Api.otNodeSetMode(self.otNode, mode.encode('utf-8')) != 0:
raise OSError("otNodeSetMode failed!")
def interface_up(self):
if self.Api.otNodeInterfaceUp(self.otNode) != 0:
raise OSError("otNodeInterfaceUp failed!")
def interface_down(self):
if self.Api.otNodeInterfaceDown(self.otNode) != 0:
raise OSError("otNodeInterfaceDown failed!")
def thread_start(self):
if self.Api.otNodeThreadStart(self.otNode) != 0:
raise OSError("otNodeThreadStart failed!")
def thread_stop(self):
if self.Api.otNodeThreadStop(self.otNode) != 0:
raise OSError("otNodeThreadStop failed!")
def commissioner_start(self):
if self.Api.otNodeCommissionerStart(self.otNode) != 0:
raise OSError("otNodeCommissionerStart failed!")
def commissioner_add_joiner(self, addr, psk):
if self.Api.otNodeCommissionerJoinerAdd(self.otNode, addr.encode('utf-8'), psk.encode('utf-8')) != 0:
raise OSError("otNodeCommissionerJoinerAdd failed!")
def joiner_start(self, pskd='', provisioning_url=''):
if self.Api.otNodeJoinerStart(self.otNode, pskd.encode('utf-8'), provisioning_url.encode('utf-8')) != 0:
raise OSError("otNodeJoinerStart failed!")
def clear_whitelist(self):
if self.Api.otNodeClearWhitelist(self.otNode) != 0:
raise OSError("otNodeClearWhitelist failed!")
def enable_whitelist(self):
if self.Api.otNodeEnableWhitelist(self.otNode) != 0:
raise OSError("otNodeEnableWhitelist failed!")
def disable_whitelist(self):
if self.Api.otNodeDisableWhitelist(self.otNode) != 0:
raise OSError("otNodeDisableWhitelist failed!")
def add_whitelist(self, addr, rssi=None):
if rssi == None:
rssi = 0
if self.Api.otNodeAddWhitelist(self.otNode, addr.encode('utf-8'), ctypes.c_byte(rssi)) != 0:
raise OSError("otNodeAddWhitelist failed!")
def remove_whitelist(self, addr):
if self.Api.otNodeRemoveWhitelist(self.otNode, addr.encode('utf-8')) != 0:
raise OSError("otNodeRemoveWhitelist failed!")
def get_addr16(self):
return self.Api.otNodeGetAddr16(self.otNode)
def get_addr64(self):
return self.Api.otNodeGetAddr64(self.otNode).decode('utf-8')
def get_hashmacaddr(self):
return self.Api.otNodeGetHashMacAddress(self.otNode).decode('utf-8')
def get_channel(self):
return self.Api.otNodeGetChannel(self.otNode)
def set_channel(self, channel):
if self.Api.otNodeSetChannel(self.otNode, ctypes.c_ubyte(channel)) != 0:
raise OSError("otNodeSetChannel failed!")
def get_masterkey(self):
return self.Api.otNodeGetMasterkey(self.otNode).decode("utf-8")
def set_masterkey(self, masterkey):
if self.Api.otNodeSetMasterkey(self.otNode, masterkey.encode('utf-8')) != 0:
raise OSError("otNodeSetMasterkey failed!")
def get_key_sequence_counter(self):
return self.Api.otNodeGetKeySequenceCounter(self.otNode)
def set_key_sequence_counter(self, key_sequence_counter):
if self.Api.otNodeSetKeySequenceCounter(self.otNode, ctypes.c_uint(key_sequence_counter)) != 0:
raise OSError("otNodeSetKeySequenceCounter failed!")
def set_key_switch_guardtime(self, key_switch_guardtime):
if self.Api.otNodeSetKeySwitchGuardTime(self.otNode, ctypes.c_uint(key_switch_guardtime)) != 0:
raise OSError("otNodeSetKeySwitchGuardTime failed!")
def set_network_id_timeout(self, network_id_timeout):
if self.Api.otNodeSetNetworkIdTimeout(self.otNode, ctypes.c_ubyte(network_id_timeout)) != 0:
raise OSError("otNodeSetNetworkIdTimeout failed!")
def get_network_name(self):
return self.Api.otNodeGetNetworkName(self.otNode).decode("utf-8")
def set_network_name(self, network_name):
if self.Api.otNodeSetNetworkName(self.otNode, network_name.encode('utf-8')) != 0:
raise OSError("otNodeSetNetworkName failed!")
def get_panid(self):
return int(self.Api.otNodeGetPanId(self.otNode))
def set_panid(self, panid):
if self.Api.otNodeSetPanId(self.otNode, ctypes.c_ushort(panid)) != 0:
raise OSError("otNodeSetPanId failed!")
def get_partition_id(self):
return int(self.Api.otNodeGetPartitionId(self.otNode))
def set_partition_id(self, partition_id):
if self.Api.otNodeSetPartitionId(self.otNode, ctypes.c_uint(partition_id)) != 0:
raise OSError("otNodeSetPartitionId failed!")
def set_router_upgrade_threshold(self, threshold):
if self.Api.otNodeSetRouterUpgradeThreshold(self.otNode, ctypes.c_ubyte(threshold)) != 0:
raise OSError("otNodeSetRouterUpgradeThreshold failed!")
def set_router_downgrade_threshold(self, threshold):
if self.Api.otNodeSetRouterDowngradeThreshold(self.otNode, ctypes.c_ubyte(threshold)) != 0:
raise OSError("otNodeSetRouterDowngradeThreshold failed!")
def release_router_id(self, router_id):
if self.Api.otNodeReleaseRouterId(self.otNode, ctypes.c_ubyte(router_id)) != 0:
raise OSError("otNodeReleaseRouterId failed!")
def get_state(self):
return self.Api.otNodeGetState(self.otNode).decode('utf-8')
def set_state(self, state):
if self.Api.otNodeSetState(self.otNode, state.encode('utf-8')) != 0:
raise OSError("otNodeSetState failed!")
def get_timeout(self):
return int(self.Api.otNodeGetTimeout(self.otNode))
def set_timeout(self, timeout):
if self.Api.otNodeSetTimeout(self.otNode, ctypes.c_uint(timeout)) != 0:
raise OSError("otNodeSetTimeout failed!")
def set_max_children(self, number):
if self.Api.otNodeSetMaxChildren(self.otNode, ctypes.c_ubyte(number)) != 0:
raise OSError("otNodeSetMaxChildren failed!")
def get_weight(self):
return int(self.Api.otNodeGetWeight(self.otNode))
def set_weight(self, weight):
if self.Api.otNodeSetWeight(self.otNode, ctypes.c_ubyte(weight)) != 0:
raise OSError("otNodeSetWeight failed!")
def add_ipaddr(self, ipaddr):
if self.Api.otNodeAddIpAddr(self.otNode, ipaddr.encode('utf-8')) != 0:
raise OSError("otNodeAddIpAddr failed!")
def get_addrs(self):
return self.Api.otNodeGetAddrs(self.otNode).decode("utf-8").split("\n")
def get_context_reuse_delay(self):
return int(self.Api.otNodeGetContextReuseDelay(self.otNode))
def set_context_reuse_delay(self, delay):
if self.Api.otNodeSetContextReuseDelay(self.otNode, ctypes.c_uint(delay)) != 0:
raise OSError("otNodeSetContextReuseDelay failed!")
def add_prefix(self, prefix, flags, prf = 'med'):
if self.Api.otNodeAddPrefix(self.otNode, prefix.encode('utf-8'), flags.encode('utf-8'), prf.encode('utf-8')) != 0:
raise OSError("otNodeAddPrefix failed!")
def remove_prefix(self, prefix):
if self.Api.otNodeRemovePrefix(self.otNode, prefix.encode('utf-8')) != 0:
raise OSError("otNodeRemovePrefix failed!")
def add_route(self, prefix, prf = 'med'):
if self.Api.otNodeAddRoute(self.otNode, prefix.encode('utf-8'), prf.encode('utf-8')) != 0:
raise OSError("otNodeAddRoute failed!")
def remove_route(self, prefix):
if self.Api.otNodeRemoveRoute(self.otNode, prefix.encode('utf-8')) != 0:
raise OSError("otNodeRemovePrefix failed!")
def register_netdata(self):
if self.Api.otNodeRegisterNetdata(self.otNode) != 0:
raise OSError("otNodeRegisterNetdata failed!")
def energy_scan(self, mask, count, period, scan_duration, ipaddr):
if self.Api.otNodeEnergyScan(self.otNode, ctypes.c_uint(mask), ctypes.c_ubyte(count), ctypes.c_ushort(period), ctypes.c_ushort(scan_duration), ipaddr.encode('utf-8')) != 0:
raise OSError("otNodeEnergyScan failed!")
def panid_query(self, panid, mask, ipaddr):
if self.Api.otNodePanIdQuery(self.otNode, ctypes.c_ushort(panid), ctypes.c_uint(mask), ipaddr.encode('utf-8')) != 0:
raise OSError("otNodePanIdQuery failed!")
def scan(self):
return self.Api.otNodeScan(self.otNode).decode("utf-8").split("\n")
def ping(self, ipaddr, num_responses=1, size=None):
if size == None:
size = 100
numberOfResponders = self.Api.otNodePing(self.otNode, ipaddr.encode('utf-8'), ctypes.c_ushort(size), ctypes.c_uint(num_responses))
return numberOfResponders >= num_responses
def set_router_selection_jitter(self, jitter):
if self.Api.otNodeSetRouterSelectionJitter(self.otNode, ctypes.c_ubyte(jitter)) != 0:
raise OSError("otNodeSetRouterSelectionJitter failed!")
def set_active_dataset(self, timestamp, panid=None, channel=None, channel_mask=None, master_key=None):
if panid == None:
panid = 0
if channel == None:
channel = 0
if channel_mask == None:
channel_mask = 0
if master_key == None:
master_key = ""
if self.Api.otNodeSetActiveDataset(
self.otNode,
ctypes.c_ulonglong(timestamp),
ctypes.c_ushort(panid),
ctypes.c_ushort(channel),
ctypes.c_uint(channel_mask),
master_key.encode('utf-8')
) != 0:
raise OSError("otNodeSetActiveDataset failed!")
def set_pending_dataset(self, pendingtimestamp, activetimestamp, panid=None, channel=None):
if pendingtimestamp == None:
pendingtimestamp = 0
if activetimestamp == None:
activetimestamp = 0
if panid == None:
panid = 0
if channel == None:
channel = 0
if self.Api.otNodeSetPendingDataset(
self.otNode,
ctypes.c_ulonglong(activetimestamp),
ctypes.c_ulonglong(pendingtimestamp),
ctypes.c_ushort(panid),
ctypes.c_ushort(channel)
) != 0:
raise OSError("otNodeSetPendingDataset failed!")
def announce_begin(self, mask, count, period, ipaddr):
if self.Api.otNodeCommissionerAnnounceBegin(self.otNode, ctypes.c_uint(mask), ctypes.c_ubyte(count), ctypes.c_ushort(period), ipaddr.encode('utf-8')) != 0:
raise OSError("otNodeCommissionerAnnounceBegin failed!")
def send_mgmt_active_set(self, active_timestamp=None, channel=None, channel_mask=None, extended_panid=None,
panid=None, master_key=None, mesh_local=None, network_name=None, binary=None):
if active_timestamp == None:
active_timestamp = 0
if panid == None:
panid = 0
if channel == None:
channel = 0
if channel_mask == None:
channel_mask = 0
if extended_panid == None:
extended_panid = ""
if master_key == None:
master_key = ""
if mesh_local == None:
mesh_local = ""
if network_name == None:
network_name = ""
if binary == None:
binary = ""
if self.Api.otNodeSendActiveSet(
self.otNode,
ctypes.c_ulonglong(active_timestamp),
ctypes.c_ushort(panid),
ctypes.c_ushort(channel),
ctypes.c_uint(channel_mask),
extended_panid.encode('utf-8'),
master_key.encode('utf-8'),
mesh_local.encode('utf-8'),
network_name.encode('utf-8'),
binary.encode('utf-8')
) != 0:
raise OSError("otNodeSendActiveSet failed!")
def send_mgmt_pending_set(self, pending_timestamp=None, active_timestamp=None, delay_timer=None, channel=None,
panid=None, master_key=None, mesh_local=None, network_name=None):
if pending_timestamp == None:
pending_timestamp = 0
if active_timestamp == None:
active_timestamp = 0
if delay_timer == None:
delay_timer = 0
if panid == None:
panid = 0
if channel == None:
channel = 0
if master_key == None:
master_key = ""
if mesh_local == None:
mesh_local = ""
if network_name == None:
network_name = ""
if self.Api.otNodeSendPendingSet(
self.otNode,
ctypes.c_ulonglong(active_timestamp),
ctypes.c_ulonglong(pending_timestamp),
ctypes.c_uint(delay_timer),
ctypes.c_ushort(panid),
ctypes.c_ushort(channel),
master_key.encode('utf-8'),
mesh_local.encode('utf-8'),
network_name.encode('utf-8')
) != 0:
raise OSError("otNodeSendPendingSet failed!")
def log(self, message):
self.Api.otNodeLog(message)
def __init_dll(self, nodeid):
""" Initialize the API from a Windows DLL. """
# Load the DLL
self.Api = ctypes.WinDLL("otnodeapi.dll")
if self.Api == None:
raise OSError("Failed to load otnodeapi.dll!")
# Define the functions
self.Api.otNodeLog.argtypes = [ctypes.c_char_p]
self.Api.otNodeInit.argtypes = [ctypes.c_uint]
self.Api.otNodeInit.restype = ctypes.c_void_p
self.Api.otNodeFinalize.argtypes = [ctypes.c_void_p]
self.Api.otNodeSetMode.argtypes = [ctypes.c_void_p,
ctypes.c_char_p]
self.Api.otNodeInterfaceUp.argtypes = [ctypes.c_void_p]
self.Api.otNodeInterfaceDown.argtypes = [ctypes.c_void_p]
self.Api.otNodeThreadStart.argtypes = [ctypes.c_void_p]
self.Api.otNodeThreadStop.argtypes = [ctypes.c_void_p]
self.Api.otNodeCommissionerStart.argtypes = [ctypes.c_void_p]
self.Api.otNodeCommissionerJoinerAdd.argtypes = [ctypes.c_void_p,
ctypes.c_char_p,
ctypes.c_char_p]
self.Api.otNodeCommissionerStop.argtypes = [ctypes.c_void_p]
self.Api.otNodeJoinerStart.argtypes = [ctypes.c_void_p,
ctypes.c_char_p,
ctypes.c_char_p]
self.Api.otNodeJoinerStop.argtypes = [ctypes.c_void_p]
self.Api.otNodeClearWhitelist.argtypes = [ctypes.c_void_p]
self.Api.otNodeEnableWhitelist.argtypes = [ctypes.c_void_p]
self.Api.otNodeDisableWhitelist.argtypes = [ctypes.c_void_p]
self.Api.otNodeAddWhitelist.argtypes = [ctypes.c_void_p,
ctypes.c_char_p,
ctypes.c_byte]
self.Api.otNodeRemoveWhitelist.argtypes = [ctypes.c_void_p,
ctypes.c_char_p]
self.Api.otNodeGetAddr16.argtypes = [ctypes.c_void_p]
self.Api.otNodeGetAddr16.restype = ctypes.c_ushort
self.Api.otNodeGetAddr64.argtypes = [ctypes.c_void_p]
self.Api.otNodeGetAddr64.restype = ctypes.c_char_p
self.Api.otNodeGetHashMacAddress.argtypes = [ctypes.c_void_p]
self.Api.otNodeGetHashMacAddress.restype = ctypes.c_char_p
self.Api.otNodeSetChannel.argtypes = [ctypes.c_void_p,
ctypes.c_ubyte]
self.Api.otNodeGetChannel.argtypes = [ctypes.c_void_p]
self.Api.otNodeGetChannel.restype = ctypes.c_ubyte
self.Api.otNodeSetMasterkey.argtypes = [ctypes.c_void_p,
ctypes.c_char_p]
self.Api.otNodeGetMasterkey.argtypes = [ctypes.c_void_p]
self.Api.otNodeGetMasterkey.restype = ctypes.c_char_p
self.Api.otNodeGetKeySequenceCounter.argtypes = [ctypes.c_void_p]
self.Api.otNodeGetKeySequenceCounter.restype = ctypes.c_uint
self.Api.otNodeSetKeySequenceCounter.argtypes = [ctypes.c_void_p,
ctypes.c_uint]
self.Api.otNodeSetKeySwitchGuardTime.argtypes = [ctypes.c_void_p,
ctypes.c_uint]
self.Api.otNodeSetNetworkIdTimeout.argtypes = [ctypes.c_void_p,
ctypes.c_ubyte]
self.Api.otNodeGetNetworkName.argtypes = [ctypes.c_void_p]
self.Api.otNodeGetNetworkName.restype = ctypes.c_char_p
self.Api.otNodeSetNetworkName.argtypes = [ctypes.c_void_p,
ctypes.c_char_p]
self.Api.otNodeGetPanId.argtypes = [ctypes.c_void_p]
self.Api.otNodeGetPanId.restype = ctypes.c_ushort
self.Api.otNodeSetPanId.argtypes = [ctypes.c_void_p,
ctypes.c_ushort]
self.Api.otNodeGetPartitionId.argtypes = [ctypes.c_void_p]
self.Api.otNodeGetPartitionId.restype = ctypes.c_uint
self.Api.otNodeSetPartitionId.argtypes = [ctypes.c_void_p,
ctypes.c_uint]
self.Api.otNodeSetRouterUpgradeThreshold.argtypes = [ctypes.c_void_p,
ctypes.c_ubyte]
self.Api.otNodeSetRouterDowngradeThreshold.argtypes = [ctypes.c_void_p,
ctypes.c_ubyte]
self.Api.otNodeReleaseRouterId.argtypes = [ctypes.c_void_p,
ctypes.c_ubyte]
self.Api.otNodeGetState.argtypes = [ctypes.c_void_p]
self.Api.otNodeGetState.restype = ctypes.c_char_p
self.Api.otNodeSetState.argtypes = [ctypes.c_void_p,
ctypes.c_char_p]
self.Api.otNodeGetTimeout.argtypes = [ctypes.c_void_p]
self.Api.otNodeGetTimeout.restype = ctypes.c_uint
self.Api.otNodeSetTimeout.argtypes = [ctypes.c_void_p,
ctypes.c_uint]
self.Api.otNodeGetWeight.argtypes = [ctypes.c_void_p]
self.Api.otNodeGetWeight.restype = ctypes.c_ubyte
self.Api.otNodeSetWeight.argtypes = [ctypes.c_void_p,
ctypes.c_ubyte]
self.Api.otNodeAddIpAddr.argtypes = [ctypes.c_void_p,
ctypes.c_char_p]
self.Api.otNodeGetAddrs.argtypes = [ctypes.c_void_p]
self.Api.otNodeGetAddrs.restype = ctypes.c_char_p
self.Api.otNodeGetContextReuseDelay.argtypes = [ctypes.c_void_p]
self.Api.otNodeGetContextReuseDelay.restype = ctypes.c_uint
self.Api.otNodeSetContextReuseDelay.argtypes = [ctypes.c_void_p,
ctypes.c_uint]
self.Api.otNodeAddPrefix.argtypes = [ctypes.c_void_p,
ctypes.c_char_p,
ctypes.c_char_p,
ctypes.c_char_p]
self.Api.otNodeRemovePrefix.argtypes = [ctypes.c_void_p,
ctypes.c_char_p]
self.Api.otNodeAddRoute.argtypes = [ctypes.c_void_p,
ctypes.c_char_p,
ctypes.c_char_p]
self.Api.otNodeRemoveRoute.argtypes = [ctypes.c_void_p,
ctypes.c_char_p]
self.Api.otNodeRegisterNetdata.argtypes = [ctypes.c_void_p]
self.Api.otNodeEnergyScan.argtypes = [ctypes.c_void_p,
ctypes.c_uint,
ctypes.c_ubyte,
ctypes.c_ushort,
ctypes.c_ushort,
ctypes.c_char_p]
self.Api.otNodePanIdQuery.argtypes = [ctypes.c_void_p,
ctypes.c_ushort,
ctypes.c_uint,
ctypes.c_char_p]
self.Api.otNodeScan.argtypes = [ctypes.c_void_p]
self.Api.otNodeScan.restype = ctypes.c_char_p
self.Api.otNodePing.argtypes = [ctypes.c_void_p,
ctypes.c_char_p,
ctypes.c_ushort,
ctypes.c_uint]
self.Api.otNodePing.restype = ctypes.c_uint
self.Api.otNodeSetRouterSelectionJitter.argtypes = [ctypes.c_void_p,
ctypes.c_ubyte]
self.Api.otNodeCommissionerAnnounceBegin.argtypes = [ctypes.c_void_p,
ctypes.c_uint,
ctypes.c_ubyte,
ctypes.c_ushort,
ctypes.c_char_p]
self.Api.otNodeSetActiveDataset.argtypes = [ctypes.c_void_p,
ctypes.c_ulonglong,
ctypes.c_ushort,
ctypes.c_ushort,
ctypes.c_uint,
ctypes.c_char_p]
self.Api.otNodeSetPendingDataset.argtypes = [ctypes.c_void_p,
ctypes.c_ulonglong,
ctypes.c_ulonglong,
ctypes.c_ushort,
ctypes.c_ushort]
self.Api.otNodeSendPendingSet.argtypes = [ctypes.c_void_p,
ctypes.c_ulonglong,
ctypes.c_ulonglong,
ctypes.c_uint,
ctypes.c_ushort,
ctypes.c_ushort,
ctypes.c_char_p,
ctypes.c_char_p,
ctypes.c_char_p]
self.Api.otNodeSendActiveSet.argtypes = [ctypes.c_void_p,
ctypes.c_ulonglong,
ctypes.c_ushort,
ctypes.c_ushort,
ctypes.c_uint,
ctypes.c_char_p,
ctypes.c_char_p,
ctypes.c_char_p,
ctypes.c_char_p,
ctypes.c_char_p]
self.Api.otNodeSetMaxChildren.argtypes = [ctypes.c_void_p,
ctypes.c_ubyte]
# Initialize a new node
self.otNode = self.Api.otNodeInit(ctypes.c_uint(nodeid))
if self.otNode == None:
raise OSError("otNodeInit failed!")
+581
View File
@@ -0,0 +1,581 @@
#!/usr/bin/python
#
# Copyright (c) 2016, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
import os
import sys
import time
import pexpect
class otCli:
def __init__(self, nodeid):
self.nodeid = nodeid
self.verbose = int(float(os.getenv('VERBOSE', 0)))
self.node_type = os.getenv('NODE_TYPE', 'sim')
if self.node_type == 'soc':
self.__init_soc(nodeid)
elif self.node_type == 'ncp-sim':
self.__init_ncp_sim(nodeid)
else:
self.__init_sim(nodeid)
if self.verbose:
self.pexpect.logfile_read = sys.stdout
def __init_sim(self, nodeid):
""" Initialize a simulation node. """
if "OT_CLI_PATH" in os.environ.keys():
cmd = os.environ['OT_CLI_PATH']
elif "top_builddir" in os.environ.keys():
srcdir = os.environ['top_builddir']
cmd = '%s/examples/apps/cli/ot-cli-ftd' % srcdir
else:
cmd = './ot-cli-ftd'
cmd += ' %d' % nodeid
print ("%s" % cmd)
self.pexpect = pexpect.spawn(cmd, timeout=4)
# Add delay to ensure that the process is ready to receive commands.
time.sleep(0.2)
def __init_ncp_sim(self, nodeid):
""" Initialize an NCP simulation node. """
if "top_builddir" in os.environ.keys():
builddir = os.environ['top_builddir']
if "top_srcdir" in os.environ.keys():
srcdir = os.environ['top_srcdir']
else:
srcdir = os.path.dirname(os.path.realpath(__file__))
srcdir += "/../../.."
cmd = 'python %s/tools/spinel-cli/spinel-cli.py -p %s/examples/apps/ncp/ot-ncp -n' % (srcdir, builddir)
else:
cmd = './ot-ncp'
cmd += ' %d' % nodeid
print ("%s" % cmd)
self.pexpect = pexpect.spawn(cmd, timeout=4)
time.sleep(0.2)
self.pexpect.expect('spinel-cli >')
self.debug(int(os.getenv('DEBUG', '0')))
def __init_soc(self, nodeid):
""" Initialize a System-on-a-chip node connected via UART. """
import fdpexpect
serialPort = '/dev/ttyUSB%d' % ((nodeid-1)*2)
self.pexpect = fdpexpect.fdspawn(os.open(serialPort, os.O_RDWR|os.O_NONBLOCK|os.O_NOCTTY))
def __del__(self):
if self.pexpect.isalive():
self.send_command('exit')
self.pexpect.expect(pexpect.EOF)
self.pexpect.terminate()
self.pexpect.close(force=True)
def send_command(self, cmd):
print ("%d: %s" % (self.nodeid, cmd))
self.pexpect.sendline(cmd)
def get_commands(self):
self.send_command('?')
self.pexpect.expect('Commands:')
commands = []
while True:
i = self.pexpect.expect(['Done', '(\S+)'])
if i != 0:
commands.append(self.pexpect.match.groups()[0])
else:
break
return commands
def set_mode(self, mode):
cmd = 'mode ' + mode
self.send_command(cmd)
self.pexpect.expect('Done')
def debug(self, level):
self.send_command('debug '+str(level))
def interface_up(self):
self.send_command('ifconfig up')
self.pexpect.expect('Done')
def interface_down(self):
self.send_command('ifconfig down')
self.pexpect.expect('Done')
def thread_start(self):
self.send_command('thread start')
self.pexpect.expect('Done')
def thread_stop(self):
self.send_command('thread stop')
self.pexpect.expect('Done')
def commissioner_start(self):
cmd = 'commissioner start'
self.send_command(cmd)
self.pexpect.expect('Done')
def commissioner_add_joiner(self, addr, psk):
cmd = 'commissioner joiner add ' + addr + ' ' + psk
self.send_command(cmd)
self.pexpect.expect('Done')
def joiner_start(self, pskd='', provisioning_url=''):
cmd = 'joiner start ' + pskd + ' ' + provisioning_url
self.send_command(cmd)
self.pexpect.expect('Done')
def clear_whitelist(self):
self.send_command('whitelist clear')
self.pexpect.expect('Done')
def enable_whitelist(self):
self.send_command('whitelist enable')
self.pexpect.expect('Done')
def disable_whitelist(self):
self.send_command('whitelist disable')
self.pexpect.expect('Done')
def add_whitelist(self, addr, rssi=None):
cmd = 'whitelist add ' + addr
if rssi != None:
cmd += ' ' + str(rssi)
self.send_command(cmd)
self.pexpect.expect('Done')
def remove_whitelist(self, addr):
cmd = 'whitelist remove ' + addr
self.send_command(cmd)
self.pexpect.expect('Done')
def get_addr16(self):
self.send_command('rloc16')
i = self.pexpect.expect('([0-9a-fA-F]{4})')
if i == 0:
addr16 = int(self.pexpect.match.groups()[0], 16)
self.pexpect.expect('Done')
return addr16
def get_addr64(self):
self.send_command('extaddr')
i = self.pexpect.expect('([0-9a-fA-F]{16})')
if i == 0:
addr64 = self.pexpect.match.groups()[0].decode("utf-8")
self.pexpect.expect('Done')
return addr64
def get_hashmacaddr(self):
self.send_command('hashmacaddr')
i = self.pexpect.expect('([0-9a-fA-F]{16})')
if i == 0:
addr = self.pexpect.match.groups()[0].decode("utf-8")
self.pexpect.expect('Done')
return addr
def get_channel(self):
self.send_command('channel')
i = self.pexpect.expect('(\d+)\r\n')
if i == 0:
channel = int(self.pexpect.match.groups()[0])
self.pexpect.expect('Done')
return channel
def set_channel(self, channel):
cmd = 'channel %d' % channel
self.send_command(cmd)
self.pexpect.expect('Done')
def get_masterkey(self):
self.send_command('masterkey')
i = self.pexpect.expect('([0-9a-fA-F]{32})')
if i == 0:
masterkey = self.pexpect.match.groups()[0].decode("utf-8")
self.pexpect.expect('Done')
return masterkey
def set_masterkey(self, masterkey):
cmd = 'masterkey ' + masterkey
self.send_command(cmd)
self.pexpect.expect('Done')
def get_key_sequence_counter(self):
self.send_command('keysequence counter')
i = self.pexpect.expect('(\d+)\r\n')
if i == 0:
key_sequence_counter = int(self.pexpect.match.groups()[0])
self.pexpect.expect('Done')
return key_sequence_counter
def set_key_sequence_counter(self, key_sequence_counter):
cmd = 'keysequence counter %d' % key_sequence_counter
self.send_command(cmd)
self.pexpect.expect('Done')
def set_key_switch_guardtime(self, key_switch_guardtime):
cmd = 'keysequence guardtime %d' % key_switch_guardtime
self.send_command(cmd)
self.pexpect.expect('Done')
def set_network_id_timeout(self, network_id_timeout):
cmd = 'networkidtimeout %d' % network_id_timeout
self.send_command(cmd)
self.pexpect.expect('Done')
def get_network_name(self):
self.send_command('networkname')
while True:
i = self.pexpect.expect(['Done', '(\S+)'])
if i != 0:
network_name = self.pexpect.match.groups()[0].decode('utf-8')
else:
break
return network_name
def set_network_name(self, network_name):
cmd = 'networkname ' + network_name
self.send_command(cmd)
self.pexpect.expect('Done')
def get_panid(self):
self.send_command('panid')
i = self.pexpect.expect('([0-9a-fA-F]{4})')
if i == 0:
panid = int(self.pexpect.match.groups()[0], 16)
self.pexpect.expect('Done')
return panid
def set_panid(self, panid):
cmd = 'panid %d' % panid
self.send_command(cmd)
self.pexpect.expect('Done')
def get_partition_id(self):
self.send_command('leaderpartitionid')
i = self.pexpect.expect('(\d+)\r\n')
if i == 0:
weight = self.pexpect.match.groups()[0]
self.pexpect.expect('Done')
return weight
def set_partition_id(self, partition_id):
cmd = 'leaderpartitionid %d' % partition_id
self.send_command(cmd)
self.pexpect.expect('Done')
def set_router_upgrade_threshold(self, threshold):
cmd = 'routerupgradethreshold %d' % threshold
self.send_command(cmd)
self.pexpect.expect('Done')
def set_router_downgrade_threshold(self, threshold):
cmd = 'routerdowngradethreshold %d' % threshold
self.send_command(cmd)
self.pexpect.expect('Done')
def release_router_id(self, router_id):
cmd = 'releaserouterid %d' % router_id
self.send_command(cmd)
self.pexpect.expect('Done')
def get_state(self):
states = ['detached', 'child', 'router', 'leader']
self.send_command('state')
match = self.pexpect.expect(states)
self.pexpect.expect('Done')
return states[match]
def set_state(self, state):
cmd = 'state ' + state
self.send_command(cmd)
self.pexpect.expect('Done')
def get_timeout(self):
self.send_command('childtimeout')
i = self.pexpect.expect('(\d+)\r\n')
if i == 0:
timeout = self.pexpect.match.groups()[0]
self.pexpect.expect('Done')
return timeout
def set_timeout(self, timeout):
cmd = 'childtimeout %d' % timeout
self.send_command(cmd)
self.pexpect.expect('Done')
def set_max_children(self, number):
cmd = 'childmax %d' % number
self.send_command(cmd)
self.pexpect.expect('Done')
def get_weight(self):
self.send_command('leaderweight')
i = self.pexpect.expect('(\d+)\r\n')
if i == 0:
weight = self.pexpect.match.groups()[0]
self.pexpect.expect('Done')
return weight
def set_weight(self, weight):
cmd = 'leaderweight %d' % weight
self.send_command(cmd)
self.pexpect.expect('Done')
def add_ipaddr(self, ipaddr):
cmd = 'ipaddr add ' + ipaddr
self.send_command(cmd)
self.pexpect.expect('Done')
def get_addrs(self):
addrs = []
self.send_command('ipaddr')
while True:
i = self.pexpect.expect(['(\S+:\S+)\r\n', 'Done'])
if i == 0:
addrs.append(self.pexpect.match.groups()[0].decode("utf-8"))
elif i == 1:
break
return addrs
def get_context_reuse_delay(self):
self.send_command('contextreusedelay')
i = self.pexpect.expect('(\d+)\r\n')
if i == 0:
timeout = self.pexpect.match.groups()[0]
self.pexpect.expect('Done')
return timeout
def set_context_reuse_delay(self, delay):
cmd = 'contextreusedelay %d' % delay
self.send_command(cmd)
self.pexpect.expect('Done')
def add_prefix(self, prefix, flags, prf = 'med'):
cmd = 'prefix add ' + prefix + ' ' + flags + ' ' + prf
self.send_command(cmd)
self.pexpect.expect('Done')
def remove_prefix(self, prefix):
cmd = ' prefix remove ' + prefix
self.send_command(cmd)
self.pexpect.expect('Done')
def add_route(self, prefix, prf = 'med'):
cmd = 'route add ' + prefix + ' ' + prf
self.send_command(cmd)
self.pexpect.expect('Done')
def remove_route(self, prefix):
cmd = 'route remove ' + prefix
self.send_command(cmd)
self.pexpect.expect('Done')
def register_netdata(self):
self.send_command('netdataregister')
self.pexpect.expect('Done')
def energy_scan(self, mask, count, period, scan_duration, ipaddr):
cmd = 'commissioner energy ' + str(mask) + ' ' + str(count) + ' ' + str(period) + ' ' + str(scan_duration) + ' ' + ipaddr
self.send_command(cmd)
self.pexpect.expect('Energy:', timeout=8)
def panid_query(self, panid, mask, ipaddr):
cmd = 'commissioner panid ' + str(panid) + ' ' + str(mask) + ' ' + ipaddr
self.send_command(cmd)
self.pexpect.expect('Conflict:', timeout=8)
def scan(self):
self.send_command('scan')
results = []
while True:
i = self.pexpect.expect(['\|\s(\S+)\s+\|\s(\S+)\s+\|\s([0-9a-fA-F]{4})\s\|\s([0-9a-fA-F]{16})\s\|\s(\d+)\r\n',
'Done'])
if i == 0:
results.append(self.pexpect.match.groups())
else:
break
return results
def ping(self, ipaddr, num_responses=1, size=None):
cmd = 'ping ' + ipaddr
if size != None:
cmd += ' ' + str(size)
self.send_command(cmd)
result = True
try:
responders = {}
while len(responders) < num_responses:
i = self.pexpect.expect(['from (\S+):'])
if i == 0:
responders[self.pexpect.match.groups()[0]] = 1
self.pexpect.expect('\n')
except pexpect.TIMEOUT:
result = False
return result
def set_router_selection_jitter(self, jitter):
cmd = 'routerselectionjitter %d' % jitter
self.send_command(cmd)
self.pexpect.expect('Done')
def set_active_dataset(self, timestamp, panid=None, channel=None, channel_mask=None, master_key=None):
self.send_command('dataset clear')
self.pexpect.expect('Done')
cmd = 'dataset activetimestamp %d' % timestamp
self.send_command(cmd)
self.pexpect.expect('Done')
if panid != None:
cmd = 'dataset panid %d' % panid
self.send_command(cmd)
self.pexpect.expect('Done')
if channel != None:
cmd = 'dataset channel %d' % channel
self.send_command(cmd)
self.pexpect.expect('Done')
if channel_mask != None:
cmd = 'dataset channelmask %d' % channel_mask
self.send_command(cmd)
self.pexpect.expect('Done')
if master_key != None:
cmd = 'dataset masterkey ' + master_key
self.send_command(cmd)
self.pexpect.expect('Done')
self.send_command('dataset commit active')
self.pexpect.expect('Done')
def set_pending_dataset(self, pendingtimestamp, activetimestamp, panid=None, channel=None):
self.send_command('dataset clear')
self.pexpect.expect('Done')
cmd = 'dataset pendingtimestamp %d' % pendingtimestamp
self.send_command(cmd)
self.pexpect.expect('Done')
cmd = 'dataset activetimestamp %d' % activetimestamp
self.send_command(cmd)
self.pexpect.expect('Done')
if panid != None:
cmd = 'dataset panid %d' % panid
self.send_command(cmd)
self.pexpect.expect('Done')
if channel != None:
cmd = 'dataset channel %d' % channel
self.send_command(cmd)
self.pexpect.expect('Done')
self.send_command('dataset commit pending')
self.pexpect.expect('Done')
def announce_begin(self, mask, count, period, ipaddr):
cmd = 'commissioner announce ' + str(mask) + ' ' + str(count) + ' ' + str(period) + ' ' + ipaddr
self.send_command(cmd)
self.pexpect.expect('Done')
def send_mgmt_active_set(self, active_timestamp=None, channel=None, channel_mask=None, extended_panid=None,
panid=None, master_key=None, mesh_local=None, network_name=None, binary=None):
cmd = 'dataset mgmtsetcommand active '
if active_timestamp != None:
cmd += 'activetimestamp %d ' % active_timestamp
if channel != None:
cmd += 'channel %d ' % channel
if channel_mask != None:
cmd += 'channelmask %d ' % channel_mask
if extended_panid != None:
cmd += 'extpanid ' + extended_panid + ' '
if panid != None:
cmd += 'panid %d ' % panid
if master_key != None:
cmd += 'masterkey ' + master_key + ' '
if mesh_local != None:
cmd += 'localprefix ' + mesh_local + ' '
if network_name != None:
cmd += 'networkname ' + network_name + ' '
if binary != None:
cmd += 'binary ' + binary + ' '
self.send_command(cmd)
self.pexpect.expect('Done')
def send_mgmt_pending_set(self, pending_timestamp=None, active_timestamp=None, delay_timer=None, channel=None,
panid=None, master_key=None, mesh_local=None, network_name=None):
cmd = 'dataset mgmtsetcommand pending '
if pending_timestamp != None:
cmd += 'pendingtimestamp %d ' % pending_timestamp
if active_timestamp != None:
cmd += 'activetimestamp %d ' % active_timestamp
if delay_timer != None:
cmd += 'delaytimer %d ' % delay_timer
if channel != None:
cmd += 'channel %d ' % channel
if panid != None:
cmd += 'panid %d ' % panid
if master_key != None:
cmd += 'masterkey ' + master_key + ' '
if mesh_local != None:
cmd += 'localprefix ' + mesh_local + ' '
if network_name != None:
cmd += 'networkname ' + network_name + ' '
self.send_command(cmd)
self.pexpect.expect('Done')