GridClient.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Text;
  30. using System.Reflection;
  31. using OpenMetaverse;
  32. using log4net;
  33. using log4net.Appender;
  34. using log4net.Layout;
  35. using OpenSim.Framework;
  36. using OpenSim.Services.Interfaces;
  37. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  38. using OpenSim.Services.Connectors;
  39. namespace OpenSim.Tests.Clients.GridClient
  40. {
  41. public class GridClient
  42. {
  43. // private static readonly ILog m_log =
  44. // LogManager.GetLogger(
  45. // MethodBase.GetCurrentMethod().DeclaringType);
  46. public static void Main(string[] args)
  47. {
  48. ConsoleAppender consoleAppender = new ConsoleAppender();
  49. consoleAppender.Layout =
  50. new PatternLayout("%date [%thread] %-5level %logger [%property{NDC}] - %message%newline");
  51. log4net.Config.BasicConfigurator.Configure(consoleAppender);
  52. string serverURI = "http://127.0.0.1:8001";
  53. GridServicesConnector m_Connector = new GridServicesConnector(serverURI);
  54. GridRegion r1 = CreateRegion("Test Region 1", 1000, 1000);
  55. GridRegion r2 = CreateRegion("Test Region 2", 1001, 1000);
  56. GridRegion r3 = CreateRegion("Test Region 3", 1005, 1000);
  57. Console.WriteLine("[GRID CLIENT]: *** Registering region 1");
  58. bool success = m_Connector.RegisterRegion(UUID.Zero, r1);
  59. if (success)
  60. Console.WriteLine("[GRID CLIENT]: Successfully registered region 1");
  61. else
  62. Console.WriteLine("[GRID CLIENT]: region 1 failed to register");
  63. Console.WriteLine("[GRID CLIENT]: *** Registering region 2");
  64. success = m_Connector.RegisterRegion(UUID.Zero, r2);
  65. if (success)
  66. Console.WriteLine("[GRID CLIENT]: Successfully registered region 2");
  67. else
  68. Console.WriteLine("[GRID CLIENT]: region 2 failed to register");
  69. Console.WriteLine("[GRID CLIENT]: *** Registering region 3");
  70. success = m_Connector.RegisterRegion(UUID.Zero, r3);
  71. if (success)
  72. Console.WriteLine("[GRID CLIENT]: Successfully registered region 3");
  73. else
  74. Console.WriteLine("[GRID CLIENT]: region 3 failed to register");
  75. Console.WriteLine("[GRID CLIENT]: *** Deregistering region 3");
  76. success = m_Connector.DeregisterRegion(r3.RegionID);
  77. if (success)
  78. Console.WriteLine("[GRID CLIENT]: Successfully deregistered region 3");
  79. else
  80. Console.WriteLine("[GRID CLIENT]: region 3 failed to deregister");
  81. Console.WriteLine("[GRID CLIENT]: *** Registering region 3 again");
  82. success = m_Connector.RegisterRegion(UUID.Zero, r3);
  83. if (success)
  84. Console.WriteLine("[GRID CLIENT]: Successfully registered region 3");
  85. else
  86. Console.WriteLine("[GRID CLIENT]: region 3 failed to register");
  87. Console.WriteLine("[GRID CLIENT]: *** GetNeighbours of region 1");
  88. List<GridRegion> regions = m_Connector.GetNeighbours(UUID.Zero, r1.RegionID);
  89. if (regions == null)
  90. Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1 failed");
  91. else if (regions.Count > 0)
  92. {
  93. if (regions.Count != 1)
  94. Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1 returned more neighbours than expected: " + regions.Count);
  95. else
  96. Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1 returned the right neighbour " + regions[0].RegionName);
  97. }
  98. else
  99. Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1 returned 0 neighbours");
  100. Console.WriteLine("[GRID CLIENT]: *** GetRegionByUUID of region 2 (this should succeed)");
  101. GridRegion region = m_Connector.GetRegionByUUID(UUID.Zero, r2.RegionID);
  102. if (region == null)
  103. Console.WriteLine("[GRID CLIENT]: GetRegionByUUID returned null");
  104. else
  105. Console.WriteLine("[GRID CLIENT]: GetRegionByUUID returned region " + region.RegionName);
  106. Console.WriteLine("[GRID CLIENT]: *** GetRegionByUUID of non-existent region (this should fail)");
  107. region = m_Connector.GetRegionByUUID(UUID.Zero, UUID.Random());
  108. if (region == null)
  109. Console.WriteLine("[GRID CLIENT]: GetRegionByUUID returned null");
  110. else
  111. Console.WriteLine("[GRID CLIENT]: GetRegionByUUID returned region " + region.RegionName);
  112. Console.WriteLine("[GRID CLIENT]: *** GetRegionByName of region 3 (this should succeed)");
  113. region = m_Connector.GetRegionByName(UUID.Zero, r3.RegionName);
  114. if (region == null)
  115. Console.WriteLine("[GRID CLIENT]: GetRegionByName returned null");
  116. else
  117. Console.WriteLine("[GRID CLIENT]: GetRegionByName returned region " + region.RegionName);
  118. Console.WriteLine("[GRID CLIENT]: *** GetRegionByName of non-existent region (this should fail)");
  119. region = m_Connector.GetRegionByName(UUID.Zero, "Foo");
  120. if (region == null)
  121. Console.WriteLine("[GRID CLIENT]: GetRegionByName returned null");
  122. else
  123. Console.WriteLine("[GRID CLIENT]: GetRegionByName returned region " + region.RegionName);
  124. Console.WriteLine("[GRID CLIENT]: *** GetRegionsByName (this should return 3 regions)");
  125. regions = m_Connector.GetRegionsByName(UUID.Zero, "Test", 10);
  126. if (regions == null)
  127. Console.WriteLine("[GRID CLIENT]: GetRegionsByName returned null");
  128. else
  129. Console.WriteLine("[GRID CLIENT]: GetRegionsByName returned " + regions.Count + " regions");
  130. Console.WriteLine("[GRID CLIENT]: *** GetRegionRange (this should return 2 regions)");
  131. regions = m_Connector.GetRegionRange(UUID.Zero,
  132. 900 * (int)Constants.RegionSize, 1002 * (int) Constants.RegionSize,
  133. 900 * (int)Constants.RegionSize, 1002 * (int) Constants.RegionSize);
  134. if (regions == null)
  135. Console.WriteLine("[GRID CLIENT]: GetRegionRange returned null");
  136. else
  137. Console.WriteLine("[GRID CLIENT]: GetRegionRange returned " + regions.Count + " regions");
  138. Console.WriteLine("[GRID CLIENT]: *** GetRegionRange (this should return 0 regions)");
  139. regions = m_Connector.GetRegionRange(UUID.Zero,
  140. 900 * (int)Constants.RegionSize, 950 * (int)Constants.RegionSize,
  141. 900 * (int)Constants.RegionSize, 950 * (int)Constants.RegionSize);
  142. if (regions == null)
  143. Console.WriteLine("[GRID CLIENT]: GetRegionRange returned null");
  144. else
  145. Console.WriteLine("[GRID CLIENT]: GetRegionRange returned " + regions.Count + " regions");
  146. Console.Write("Proceed to deregister? Press enter...");
  147. Console.ReadLine();
  148. // Deregister them all
  149. Console.WriteLine("[GRID CLIENT]: *** Deregistering region 1");
  150. success = m_Connector.DeregisterRegion(r1.RegionID);
  151. if (success)
  152. Console.WriteLine("[GRID CLIENT]: Successfully deregistered region 1");
  153. else
  154. Console.WriteLine("[GRID CLIENT]: region 1 failed to deregister");
  155. Console.WriteLine("[GRID CLIENT]: *** Deregistering region 2");
  156. success = m_Connector.DeregisterRegion(r2.RegionID);
  157. if (success)
  158. Console.WriteLine("[GRID CLIENT]: Successfully deregistered region 2");
  159. else
  160. Console.WriteLine("[GRID CLIENT]: region 2 failed to deregister");
  161. Console.WriteLine("[GRID CLIENT]: *** Deregistering region 3");
  162. success = m_Connector.DeregisterRegion(r3.RegionID);
  163. if (success)
  164. Console.WriteLine("[GRID CLIENT]: Successfully deregistered region 3");
  165. else
  166. Console.WriteLine("[GRID CLIENT]: region 3 failed to deregister");
  167. }
  168. private static GridRegion CreateRegion(string name, uint xcell, uint ycell)
  169. {
  170. GridRegion region = new GridRegion(xcell, ycell);
  171. region.RegionName = name;
  172. region.RegionID = UUID.Random();
  173. region.ExternalHostName = "127.0.0.1";
  174. region.HttpPort = 9000;
  175. region.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 9000);
  176. return region;
  177. }
  178. }
  179. }