Skip to content

Commit

Permalink
clarify the IP addresses for client and PAA
Browse files Browse the repository at this point in the history
  • Loading branch information
smdn committed Jun 27, 2024
1 parent d7f04b2 commit 6121459
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@ public class SkStackClientCommandsSKJOINTests : SkStackClientTestsBase {
[Test]
public void SKJOIN()
{
const string addressString = "FE80:0000:0000:0000:021D:1290:1234:5678";
var address = IPAddress.Parse(addressString);
const string SelfIPv6Address = "FE80:0000:0000:0000:021D:1290:0003:C890";
const string PaaIPv6Address = "FE80:0000:0000:0000:1034:5678:ABCD:EF01";

var stream = new PseudoSkStackStream();

stream.ResponseWriter.WriteLine("OK");

async Task RaisePanaSessionEstablishmentEventsAsync()
{
stream.ResponseWriter.WriteLine($"EVENT 21 {addressString} 02");
stream.ResponseWriter.WriteLine($"EVENT 02 {addressString}");
stream.ResponseWriter.WriteLine($"ERXUDP {addressString} FE80:0000:0000:0000:021D:1290:1234:5678 02CC 02CC 001D129012345678 0 0001 0");
stream.ResponseWriter.WriteLine($"EVENT 21 {SelfIPv6Address} 02");
stream.ResponseWriter.WriteLine($"EVENT 02 {SelfIPv6Address}");
stream.ResponseWriter.WriteLine($"ERXUDP {SelfIPv6Address} {PaaIPv6Address} 02CC 02CC 001D129012345678 0 0001 0");

await Task.Delay(ResponseDelayInterval);

stream.ResponseWriter.Write($"EVENT 21 "); await Task.Delay(ResponseDelayInterval);
stream.ResponseWriter.Write($"{addressString} 00"); await Task.Delay(ResponseDelayInterval);
stream.ResponseWriter.Write($"{SelfIPv6Address} 00"); await Task.Delay(ResponseDelayInterval);
stream.ResponseWriter.WriteLine();
await Task.Delay(ResponseDelayInterval);

stream.ResponseWriter.WriteLine($"ERXUDP {addressString} FE80:0000:0000:0000:021D:1290:1234:5678 02CC 02CC 001D129012345678 0 0001 0");
stream.ResponseWriter.WriteLine($"ERXUDP {SelfIPv6Address} {PaaIPv6Address} 02CC 02CC 001D129012345678 0 0001 0");
await Task.Delay(ResponseDelayInterval);

stream.ResponseWriter.Write($"EVENT "); await Task.Delay(ResponseDelayInterval);
stream.ResponseWriter.WriteLine($"25 {addressString}");
stream.ResponseWriter.WriteLine($"25 {PaaIPv6Address}");
}

using var client = new SkStackClient(stream, logger: CreateLoggerForTestCase());
Expand All @@ -55,7 +55,7 @@ async Task RaisePanaSessionEstablishmentEventsAsync()
try {
Assert.That(sender, Is.SameAs(client), nameof(sender));
Assert.That(e, Is.Not.Null, nameof(e));
Assert.That(e.PanaSessionPeerAddress, Is.EqualTo(address), nameof(e.PanaSessionPeerAddress));
Assert.That(e.PanaSessionPeerAddress, Is.EqualTo(IPAddress.Parse(PaaIPv6Address)), nameof(e.PanaSessionPeerAddress));
Assert.That(e.EventNumber, Is.EqualTo(SkStackEventNumber.PanaSessionEstablishmentCompleted), nameof(e.EventNumber));
Assert.That(client.PanaSessionPeerAddress, Is.Not.Null, nameof(client.PanaSessionPeerAddress));
Assert.That(e.PanaSessionPeerAddress, Is.EqualTo(client.PanaSessionPeerAddress), nameof(client.PanaSessionPeerAddress));
Expand All @@ -68,7 +68,7 @@ async Task RaisePanaSessionEstablishmentEventsAsync()
};

#pragma warning disable CA2012
var taskSendCommand = client.SendSKJOINAsync(address).AsTask();
var taskSendCommand = client.SendSKJOINAsync(IPAddress.Parse(PaaIPv6Address)).AsTask();

Assert.DoesNotThrowAsync(
async () => await Task.WhenAll(taskSendCommand, RaisePanaSessionEstablishmentEventsAsync())
Expand All @@ -78,7 +78,7 @@ async Task RaisePanaSessionEstablishmentEventsAsync()
Assert.That(thrownExceptionInEventHandler, Is.Null, nameof(thrownExceptionInEventHandler));
Assert.That(raisedEventCount, Is.EqualTo(1), nameof(raisedEventCount));

Assert.That(address, Is.EqualTo(client.PanaSessionPeerAddress), nameof(client.PanaSessionPeerAddress));
Assert.That(IPAddress.Parse(PaaIPv6Address), Is.EqualTo(client.PanaSessionPeerAddress), nameof(client.PanaSessionPeerAddress));
Assert.That(client.IsPanaSessionAlive, Is.True, nameof(client.IsPanaSessionAlive));

var response = taskSendCommand.Result;
Expand All @@ -87,38 +87,38 @@ async Task RaisePanaSessionEstablishmentEventsAsync()

Assert.That(
stream.ReadSentData(),
SequenceIs.EqualTo("SKJOIN FE80:0000:0000:0000:021D:1290:1234:5678\r\n".ToByteSequence())
SequenceIs.EqualTo($"SKJOIN {PaaIPv6Address}\r\n".ToByteSequence())
);
}

[Test]
public void SKJOIN_FailedByEVENT24()
{
const string addressString = "FE80:0000:0000:0000:021D:1290:1234:5678";
var address = IPAddress.Parse(addressString);
const string SelfIPv6Address = "FE80:0000:0000:0000:021D:1290:0003:C890";
const string PaaIPv6Address = "FE80:0000:0000:0000:1034:5678:ABCD:EF01";

var stream = new PseudoSkStackStream();

stream.ResponseWriter.WriteLine("OK");

async Task RaisePanaSessionEstablishmentEventsAsync()
{
stream.ResponseWriter.WriteLine($"EVENT 21 {addressString} 02");
stream.ResponseWriter.WriteLine($"EVENT 02 {addressString}");
stream.ResponseWriter.WriteLine($"ERXUDP {addressString} FE80:0000:0000:0000:021D:1290:1234:5678 02CC 02CC 001D129012345678 0 0001 0");
stream.ResponseWriter.WriteLine($"EVENT 21 {SelfIPv6Address} 02");
stream.ResponseWriter.WriteLine($"EVENT 02 {SelfIPv6Address}");
stream.ResponseWriter.WriteLine($"ERXUDP {SelfIPv6Address} {PaaIPv6Address} 02CC 02CC 001D129012345678 0 0001 0");

await Task.Delay(ResponseDelayInterval);

stream.ResponseWriter.WriteLine($"EVENT 21 {addressString} 00");
stream.ResponseWriter.WriteLine($"ERXUDP {addressString} FE80:0000:0000:0000:021D:1290:1234:5678 02CC 02CC 001D129012345678 0 0001 0");
stream.ResponseWriter.WriteLine($"EVENT 21 {SelfIPv6Address} 00");
stream.ResponseWriter.WriteLine($"ERXUDP {SelfIPv6Address} {PaaIPv6Address} 02CC 02CC 001D129012345678 0 0001 0");

await Task.Delay(ResponseDelayInterval);

stream.ResponseWriter.Write($"EVENT 24 ");

await Task.Delay(ResponseDelayInterval);

stream.ResponseWriter.WriteLine($"{addressString}");
stream.ResponseWriter.WriteLine($"{SelfIPv6Address}");
}

using var client = new SkStackClient(stream, logger: CreateLoggerForTestCase());
Expand All @@ -130,14 +130,14 @@ async Task RaisePanaSessionEstablishmentEventsAsync()

client.PanaSessionEstablished += (sender, e) => raisedEventCount++;

var taskSendCommand = client.SendSKJOINAsync(address).AsTask();
var taskSendCommand = client.SendSKJOINAsync(IPAddress.Parse(PaaIPv6Address)).AsTask();

var ex = Assert.ThrowsAsync<SkStackPanaSessionEstablishmentException>(
async () => await Task.WhenAll(taskSendCommand, RaisePanaSessionEstablishmentEventsAsync())
);

Assert.That(ex!.EventNumber, Is.EqualTo(SkStackEventNumber.PanaSessionEstablishmentError));
Assert.That(ex.Address, Is.EqualTo(address));
Assert.That(ex.Address, Is.EqualTo(IPAddress.Parse(SelfIPv6Address)));

Assert.That(raisedEventCount, Is.EqualTo(0), nameof(raisedEventCount));

Expand All @@ -146,7 +146,7 @@ async Task RaisePanaSessionEstablishmentEventsAsync()

Assert.That(
stream.ReadSentData(),
SequenceIs.EqualTo("SKJOIN FE80:0000:0000:0000:021D:1290:1234:5678\r\n".ToByteSequence())
SequenceIs.EqualTo($"SKJOIN {PaaIPv6Address}\r\n".ToByteSequence())
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ public class SkStackClientCommandsSKREJOINTests : SkStackClientTestsBase {
[Test]
public void SKREJOIN()
{
const string addressString = "FE80:0000:0000:0000:021D:1290:1234:5678";
var address = IPAddress.Parse(addressString);
const string SelfIPv6Address = "FE80:0000:0000:0000:021D:1290:0003:C890";
const string PaaIPv6Address = "FE80:0000:0000:0000:1034:5678:ABCD:EF01";

var stream = new PseudoSkStackStream();

stream.ResponseWriter.WriteLine("OK");

async Task RaisePanaSessionEstablishmentEventsAsync()
{
stream.ResponseWriter.WriteLine($"EVENT 21 {addressString} 02");
stream.ResponseWriter.WriteLine($"EVENT 02 {addressString}");
stream.ResponseWriter.WriteLine($"ERXUDP {addressString} FE80:0000:0000:0000:021D:1290:1234:5678 02CC 02CC 001D129012345678 0 0001 0");
stream.ResponseWriter.WriteLine($"EVENT 21 {SelfIPv6Address} 02");
stream.ResponseWriter.WriteLine($"EVENT 02 {SelfIPv6Address}");
stream.ResponseWriter.WriteLine($"ERXUDP {SelfIPv6Address} FE80:0000:0000:0000:021D:1290:1234:5678 02CC 02CC 001D129012345678 0 0001 0");

await Task.Delay(ResponseDelayInterval);

stream.ResponseWriter.WriteLine($"EVENT 21 {addressString} 00");
stream.ResponseWriter.WriteLine($"ERXUDP {addressString} FE80:0000:0000:0000:021D:1290:1234:5678 02CC 02CC 001D129012345678 0 0001 0");
stream.ResponseWriter.WriteLine($"EVENT 21 {SelfIPv6Address} 00");
stream.ResponseWriter.WriteLine($"ERXUDP {SelfIPv6Address} FE80:0000:0000:0000:021D:1290:1234:5678 02CC 02CC 001D129012345678 0 0001 0");

await Task.Delay(ResponseDelayInterval);

stream.ResponseWriter.Write($"EVENT 2"); await Task.Delay(ResponseDelayInterval);
stream.ResponseWriter.WriteLine($"5 {addressString}");
stream.ResponseWriter.WriteLine($"5 {PaaIPv6Address}");
}

using var client = new SkStackClient(stream, logger: CreateLoggerForTestCase());
Expand All @@ -48,7 +48,7 @@ async Task RaisePanaSessionEstablishmentEventsAsync()
try {
Assert.That(sender, Is.SameAs(client), nameof(sender));
Assert.That(e, Is.Not.Null, nameof(e));
Assert.That(e.PanaSessionPeerAddress, Is.EqualTo(address), nameof(e.PanaSessionPeerAddress));
Assert.That(e.PanaSessionPeerAddress, Is.EqualTo(IPAddress.Parse(PaaIPv6Address)), nameof(e.PanaSessionPeerAddress));
Assert.That(e.EventNumber, Is.EqualTo(SkStackEventNumber.PanaSessionEstablishmentCompleted), nameof(e.EventNumber));
Assert.That(e.PanaSessionPeerAddress, Is.EqualTo(client.PanaSessionPeerAddress), nameof(client.PanaSessionPeerAddress));
Assert.That(client.IsPanaSessionAlive, Is.True, nameof(client.IsPanaSessionAlive));
Expand Down Expand Up @@ -76,9 +76,9 @@ async Task RaisePanaSessionEstablishmentEventsAsync()
var (response, rejoinedSessionPeerAddress) = taskSendCommand.Result;

Assert.That(response.Success, Is.True);
Assert.That(address, Is.EqualTo(rejoinedSessionPeerAddress));
Assert.That(IPAddress.Parse(PaaIPv6Address), Is.EqualTo(rejoinedSessionPeerAddress));

Assert.That(address, Is.EqualTo(client.PanaSessionPeerAddress), nameof(client.PanaSessionPeerAddress));
Assert.That(IPAddress.Parse(PaaIPv6Address), Is.EqualTo(client.PanaSessionPeerAddress), nameof(client.PanaSessionPeerAddress));
Assert.That(client.IsPanaSessionAlive, Is.True, nameof(client.IsPanaSessionAlive));

Assert.That(
Expand All @@ -90,29 +90,28 @@ async Task RaisePanaSessionEstablishmentEventsAsync()
[Test]
public void SKREJOIN_FailedByEVENT24()
{
const string addressString = "FE80:0000:0000:0000:021D:1290:1234:5678";
var address = IPAddress.Parse(addressString);
const string SelfIPv6Address = "FE80:0000:0000:0000:021D:1290:1234:5678";

var stream = new PseudoSkStackStream();

stream.ResponseWriter.WriteLine("OK");

async Task RaisePanaSessionEstablishmentEventsAsync()
{
stream.ResponseWriter.WriteLine($"EVENT 21 {addressString} 02");
stream.ResponseWriter.WriteLine($"EVENT 02 {addressString}");
stream.ResponseWriter.WriteLine($"ERXUDP {addressString} FE80:0000:0000:0000:021D:1290:1234:5678 02CC 02CC 001D129012345678 0 0001 0");
stream.ResponseWriter.WriteLine($"EVENT 21 {SelfIPv6Address} 02");
stream.ResponseWriter.WriteLine($"EVENT 02 {SelfIPv6Address}");
stream.ResponseWriter.WriteLine($"ERXUDP {SelfIPv6Address} FE80:0000:0000:0000:021D:1290:1234:5678 02CC 02CC 001D129012345678 0 0001 0");

await Task.Delay(ResponseDelayInterval);

stream.ResponseWriter.WriteLine($"EVENT 21 {addressString} 00");
stream.ResponseWriter.WriteLine($"ERXUDP {addressString} FE80:0000:0000:0000:021D:1290:1234:5678 02CC 02CC 001D129012345678 0 0001 0");
stream.ResponseWriter.WriteLine($"EVENT 21 {SelfIPv6Address} 00");
stream.ResponseWriter.WriteLine($"ERXUDP {SelfIPv6Address} FE80:0000:0000:0000:021D:1290:1234:5678 02CC 02CC 001D129012345678 0 0001 0");

await Task.Delay(ResponseDelayInterval);

stream.ResponseWriter.Write($"EVEN"); await Task.Delay(ResponseDelayInterval);
stream.ResponseWriter.Write($"T 2"); await Task.Delay(ResponseDelayInterval);
stream.ResponseWriter.WriteLine($"4 {addressString}");
stream.ResponseWriter.WriteLine($"4 {SelfIPv6Address}");
}

using var client = new SkStackClient(stream, logger: CreateLoggerForTestCase());
Expand All @@ -132,7 +131,7 @@ async Task RaisePanaSessionEstablishmentEventsAsync()
#pragma warning restore CA2012

Assert.That(ex!.EventNumber, Is.EqualTo(SkStackEventNumber.PanaSessionEstablishmentError));
Assert.That(ex.Address, Is.EqualTo(address));
Assert.That(ex.Address, Is.EqualTo(IPAddress.Parse(SelfIPv6Address)));

Assert.That(raisedEventCount, Is.EqualTo(0), nameof(raisedEventCount));

Expand Down

0 comments on commit 6121459

Please sign in to comment.