GridClient.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. string msg = m_Connector.RegisterRegion(UUID.Zero, r1);
  59. if (msg == String.Empty)
  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. msg = m_Connector.RegisterRegion(UUID.Zero, r2);
  65. if (msg == String.Empty)
  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. msg = m_Connector.RegisterRegion(UUID.Zero, r3);
  71. if (msg == String.Empty)
  72. Console.WriteLine("[GRID CLIENT]: Successfully registered region 3");
  73. else
  74. Console.WriteLine("[GRID CLIENT]: region 3 failed to register");
  75. bool success;
  76. Console.WriteLine("[GRID CLIENT]: *** Deregistering region 3");
  77. success = m_Connector.DeregisterRegion(r3.RegionID);
  78. if (success)
  79. Console.WriteLine("[GRID CLIENT]: Successfully deregistered region 3");
  80. else
  81. Console.WriteLine("[GRID CLIENT]: region 3 failed to deregister");
  82. Console.WriteLine("[GRID CLIENT]: *** Registering region 3 again");
  83. msg = m_Connector.RegisterRegion(UUID.Zero, r3);
  84. if (msg == String.Empty)
  85. Console.WriteLine("[GRID CLIENT]: Successfully registered region 3");
  86. else
  87. Console.WriteLine("[GRID CLIENT]: region 3 failed to register");
  88. Console.WriteLine("[GRID CLIENT]: *** GetNeighbours of region 1");
  89. List<GridRegion> regions = m_Connector.GetNeighbours(UUID.Zero, r1.RegionID);
  90. if (regions == null)
  91. Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1 failed");
  92. else if (regions.Count > 0)
  93. {
  94. if (regions.Count != 1)
  95. Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1 returned more neighbours than expected: " + regions.Count);
  96. else
  97. Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1 returned the right neighbour " + regions[0].RegionName);
  98. }
  99. else
  100. Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1 returned 0 neighbours");
  101. Console.WriteLine("[GRID CLIENT]: *** GetRegionByUUID of region 2 (this should succeed)");
  102. GridRegion region = m_Connector.GetRegionByUUID(UUID.Zero, r2.RegionID);
  103. if (region == null)
  104. Console.WriteLine("[GRID CLIENT]: GetRegionByUUID returned null");
  105. else
  106. Console.WriteLine("[GRID CLIENT]: GetRegionByUUID returned region " + region.RegionName);
  107. Console.WriteLine("[GRID CLIENT]: *** GetRegionByUUID of non-existent region (this should fail)");
  108. region = m_Connector.GetRegionByUUID(UUID.Zero, UUID.Random());
  109. if (region == null)
  110. Console.WriteLine("[GRID CLIENT]: GetRegionByUUID returned null");
  111. else
  112. Console.WriteLine("[GRID CLIENT]: GetRegionByUUID returned region " + region.RegionName);
  113. Console.WriteLine("[GRID CLIENT]: *** GetRegionByName of region 3 (this should succeed)");
  114. region = m_Connector.GetRegionByName(UUID.Zero, r3.RegionName);
  115. if (region == null)
  116. Console.WriteLine("[GRID CLIENT]: GetRegionByName returned null");
  117. else
  118. Console.WriteLine("[GRID CLIENT]: GetRegionByName returned region " + region.RegionName);
  119. Console.WriteLine("[GRID CLIENT]: *** GetRegionByName of non-existent region (this should fail)");
  120. region = m_Connector.GetRegionByName(UUID.Zero, "Foo");
  121. if (region == null)
  122. Console.WriteLine("[GRID CLIENT]: GetRegionByName returned null");
  123. else
  124. Console.WriteLine("[GRID CLIENT]: GetRegionByName returned region " + region.RegionName);
  125. Console.WriteLine("[GRID CLIENT]: *** GetRegionsByName (this should return 3 regions)");
  126. regions = m_Connector.GetRegionsByName(UUID.Zero, "Test", 10);
  127. if (regions == null)
  128. Console.WriteLine("[GRID CLIENT]: GetRegionsByName returned null");
  129. else
  130. Console.WriteLine("[GRID CLIENT]: GetRegionsByName returned " + regions.Count + " regions");
  131. Console.WriteLine("[GRID CLIENT]: *** GetRegionRange (this should return 2 regions)");
  132. regions = m_Connector.GetRegionRange(UUID.Zero,
  133. (int)Util.RegionToWorldLoc(900), (int)Util.RegionToWorldLoc(1002),
  134. (int)Util.RegionToWorldLoc(900), (int)Util.RegionToWorldLoc(1002) );
  135. if (regions == null)
  136. Console.WriteLine("[GRID CLIENT]: GetRegionRange returned null");
  137. else
  138. Console.WriteLine("[GRID CLIENT]: GetRegionRange returned " + regions.Count + " regions");
  139. Console.WriteLine("[GRID CLIENT]: *** GetRegionRange (this should return 0 regions)");
  140. regions = m_Connector.GetRegionRange(UUID.Zero,
  141. (int)Util.RegionToWorldLoc(900), (int)Util.RegionToWorldLoc(950),
  142. (int)Util.RegionToWorldLoc(900), (int)Util.RegionToWorldLoc(950) );
  143. if (regions == null)
  144. Console.WriteLine("[GRID CLIENT]: GetRegionRange returned null");
  145. else
  146. Console.WriteLine("[GRID CLIENT]: GetRegionRange returned " + regions.Count + " regions");
  147. Console.Write("Proceed to deregister? Press enter...");
  148. Console.ReadLine();
  149. // Deregister them all
  150. Console.WriteLine("[GRID CLIENT]: *** Deregistering region 1");
  151. success = m_Connector.DeregisterRegion(r1.RegionID);
  152. if (success)
  153. Console.WriteLine("[GRID CLIENT]: Successfully deregistered region 1");
  154. else
  155. Console.WriteLine("[GRID CLIENT]: region 1 failed to deregister");
  156. Console.WriteLine("[GRID CLIENT]: *** Deregistering region 2");
  157. success = m_Connector.DeregisterRegion(r2.RegionID);
  158. if (success)
  159. Console.WriteLine("[GRID CLIENT]: Successfully deregistered region 2");
  160. else
  161. Console.WriteLine("[GRID CLIENT]: region 2 failed to deregister");
  162. Console.WriteLine("[GRID CLIENT]: *** Deregistering region 3");
  163. success = m_Connector.DeregisterRegion(r3.RegionID);
  164. if (success)
  165. Console.WriteLine("[GRID CLIENT]: Successfully deregistered region 3");
  166. else
  167. Console.WriteLine("[GRID CLIENT]: region 3 failed to deregister");
  168. }
  169. private static GridRegion CreateRegion(string name, uint xcell, uint ycell)
  170. {
  171. GridRegion region = new GridRegion(xcell, ycell);
  172. region.RegionName = name;
  173. region.RegionID = UUID.Random();
  174. region.ExternalHostName = "127.0.0.1";
  175. region.HttpPort = 9000;
  176. region.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 9000);
  177. return region;
  178. }
  179. }
  180. }