seed(TestNodeHierarchy::class); $do = Domain::where('name','a')->singleOrFail(); $zo = $do->zones->where('zone_id',100)->pop(); return $zo->addresses; } private function session_zc(): void { $ao = Address::findFTN('101:0/0@a'); $ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]); } private function session_rc(): void { $ao = Address::findFTN('100:1/0@a'); $ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]); } private function session_nc(): void { $ao = Address::findFTN('100:10/0@a'); $ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]); } private function session_hub(): void { $ao = Address::findFTN('100:10/20@a'); $ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]); } // Make sure I'm configured correctly for the rest of the tests public function test_my_addresses() { $ftns = Setup::findOrFail(config('app.id'))->system->addresses; $this->assertEquals(1,$ftns->count()); } // Get a list of active addresses in a Zone public function test_zc_addresses() { $nodes = $this->zone(); $this->assertEquals(936,$nodes->count()); } // Get a ZC with no session details, and make sure it has no parent nor children public function test_zc_no_session() { // Pick ZC without any session info - we have 0 children $ao = Address::findFTN('101:0/0@a'); $this->assertEquals($ao->role,Address::NODE_ZC); $this->assertCount(0,$ao->children()); $this->assertNull($ao->parent()); } // If we have a ZC, make sure we are routing to all it's children public function test_zc_session_children() { $this->session_zc(); $ao = Address::findFTN('101:0/0@a'); $this->assertCount(935,$ao->children()); } // An RC's parent should be the ZC, when we have session details with parent public function test_zc_rc_node_parent() { $this->session_zc(); $ao = Address::findFTN('101:1/0@a'); $this->assertEquals($ao->role,Address::NODE_RC); $this->assertEquals('101:0/0.0@a',$ao->parent()->ftn); } // Get a list of active addresses in a Region public function test_rc_session_children() { $this->session_rc(); $ao = Address::findFTN('100:1/0@a'); $this->assertEquals(185,$ao->children()->count()); } // An RCs node still collects mail from the RC public function test_rc_node_rc() { $this->session_rc(); // An RCs node should still be the RC $ao = Address::findFTN('100:1/100@a'); $this->assertEquals($ao->role,Address::NODE_ACTIVE); $this->assertEquals('100:1/0.0@a',$ao->parent()->ftn); } // An NC collects mail for its children public function test_rc_nc_node_rc() { $this->session_rc(); // A NCs parent should still be the RC $ao = Address::findFTN('100:10/0@a'); $this->assertEquals($ao->role,Address::NODE_NC); $this->assertEquals('100:1/0.0@a',$ao->parent()->ftn); } // A Hub still collects mail from NC public function test_rc_hub_node_nc() { $this->session_rc(); // A Hubs parent should still be the NC $ao = Address::findFTN('100:10/20.0@a'); $this->assertEquals($ao->role,Address::NODE_HC); $this->assertEquals('100:1/0.0@a',$ao->parent()->ftn); } // A Hub's node still collects mail from Hub public function test_rc_hub_node_hub() { $this->session_rc(); // A Hubs node should still be the Hub $ao = Address::findFTN('100:10/22.0@a'); $this->assertEquals($ao->role,Address::NODE_ACTIVE); $this->assertEquals('100:1/0.0@a',$ao->parent()->ftn); } // An RCs parent is us even if we have session details for another RC public function test_rc_parent() { $this->session_rc(); $ao = Address::findFTN('100:2/0@a'); $this->assertNull($ao->parent()?->ftn); } // If we also have session details for an NC, then there are less RC nodes public function test_rc_nc_session_children() { $this->session_rc(); $this->session_nc(); $ao = Address::findFTN('100:1/0@a'); $this->assertCount(185-36,$ao->children()); } // If we also have session details for an Hub, then there are less RC nodes public function test_rc_hub_session_children() { $this->session_rc(); $ao = Address::findFTN('100:10/20@a'); $ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]); $ao = Address::findFTN('100:1/0@a'); $this->assertCount(185-6,$ao->children()); $ao = Address::findFTN('100:10/22@a'); $this->assertEquals('100:10/20.0@a',$ao->parent()->ftn); } // If we also have session details for an Hub, then there are less RC nodes public function test_rc_hub_session_child() { $this->session_hub(); $ao = Address::findFTN('100:10/22@a'); $this->assertEquals('100:10/20.0@a',$ao->parent()->ftn); } // When we have an RC with session details, we route to all its children public function test_nc_session_children() { $this->session_nc(); $ao = Address::findFTN('100:10/0@a'); $this->assertCount(35,$ao->children()); } public function test_complex_rc_nc_hc() { $this->session_rc(); $this->session_nc(); $this->session_hub(); $ao = Address::findFTN('100:1/100.0@a'); $this->assertCount(0,$ao->children()); $this->assertEquals('100:1/0.0@a',$ao->parent()->ftn); // RC $ao = Address::findFTN('100:1/0.0@a'); $this->assertCount(186-1-30-6,$ao->children()); $ao = Address::findFTN('100:11/0.0@a'); $this->assertEquals('100:1/0.0@a',$ao->parent()->ftn); // NC $ao = Address::findFTN('100:10/0.0@a'); $this->assertCount(36-1-6,$ao->children()); $ao = Address::findFTN('100:10/10.0@a'); $this->assertEquals('100:10/0.0@a',$ao->parent()->ftn); // HC $ao = Address::findFTN('100:10/20.0@a'); $this->assertCount(6-1,$ao->children()); $ao = Address::findFTN('100:10/22.0@a'); $this->assertEquals('100:10/20.0@a',$ao->parent()->ftn); } public function test_complex_rc_nc_hc_us() { $setup = Setup::findOrFail(config('app.id')); $ao = Address::findFTN('100:10/0.0@a'); $setup->system_id = $ao->system_id; $setup->save(); $this->session_rc(); //$this->session_nc(); $this->session_hub(); $ao = Address::findFTN('100:11/0.0'); $ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]); $ao = Address::findFTN('100:1/100.0@a'); $this->assertCount(0,$ao->children()); $this->assertEquals('100:1/0.0@a',$ao->parent()?->ftn); // RC $ao = Address::findFTN('100:1/0.0@a'); $this->assertCount(186-36-36-1,$ao->children()); $ao = Address::findFTN('100:11/0.0@a'); $this->assertEquals('100:11/0.0@a',$ao->parent()->ftn); // NC $ao = Address::findFTN('100:10/0.0@a'); $this->assertCount(36-6-1,$ao->children()); $ao = Address::findFTN('100:10/10.0@a'); $this->assertNull($ao->parent()?->ftn); // HC $ao = Address::findFTN('100:10/20.0@a'); $this->assertCount(6-1,$ao->children()); $ao = Address::findFTN('100:10/22.0@a'); $this->assertEquals('100:10/20.0@a',$ao->parent()->ftn); } // A points parent is the node, if we have traffic for a point and we have session details for the node public function test_point_session_node() { //$this->session_hub(); $so = new System; $so->name = 'Point System'; $so->sysop = 'Point Sysop'; $so->location = 'Melbourne, AU'; $so->active = TRUE; $so->save(); // Create a child $ao = Address::createFTN('100:10/21.2@a',$so); $ao->region_id = 1; // @todo This should be worked out from the parent node (if exists), or another node on the same host $ao->save(); $ao = Address::findFTN('100:10/21.0@a'); $ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]); $ao = Address::findFTN('100:10/21.2@a'); $this->assertEquals('100:10/21.0@a',$ao->parent()?->ftn); $ao = Address::findFTN('100:10/21@a'); $this->assertCount(1,$ao->children()); } }