2021-07-15 14:54:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Database\Seeders;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
use App\Models\{Address, Domain, Setup, System, Zone};
|
2021-07-15 14:54:23 +00:00
|
|
|
|
2023-10-17 12:19:28 +00:00
|
|
|
class TestNodeHierarchy extends Seeder
|
2021-07-15 14:54:23 +00:00
|
|
|
{
|
2023-11-21 23:40:15 +00:00
|
|
|
public const DEBUG=FALSE;
|
2022-11-19 13:19:09 +00:00
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
/**
|
|
|
|
* Run the database seeds.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
DB::table('domains')
|
|
|
|
->insert([
|
2023-11-21 23:40:15 +00:00
|
|
|
'name'=>'a',
|
2021-07-15 14:54:23 +00:00
|
|
|
'active'=>TRUE,
|
|
|
|
'public'=>TRUE,
|
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
DB::table('domains')
|
|
|
|
->insert([
|
2023-11-21 23:40:15 +00:00
|
|
|
'name'=>'b',
|
2021-07-15 14:54:23 +00:00
|
|
|
'active'=>TRUE,
|
|
|
|
'public'=>TRUE,
|
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
foreach (['a','b'] as $domain) {
|
2022-11-11 11:57:40 +00:00
|
|
|
$do = Domain::where('name',$domain)->singleOrFail();
|
|
|
|
$this->hierarchy($do,100);
|
|
|
|
$this->hierarchy($do,101);
|
2021-07-15 14:54:23 +00:00
|
|
|
}
|
2023-11-21 23:40:15 +00:00
|
|
|
|
|
|
|
// Configure my addresses
|
|
|
|
$so = Setup::findOrFail(config('app.id'));
|
|
|
|
$ao = Address::findFTN('100:0/0@a');
|
|
|
|
$so->system_id = $ao->system_id;
|
|
|
|
$so->save();
|
|
|
|
|
|
|
|
// Add file area
|
|
|
|
DB::table('fileareas')
|
|
|
|
->insert([
|
|
|
|
'name'=>'FILE_AREA',
|
|
|
|
'description'=>'Testing File Area',
|
|
|
|
'active'=>TRUE,
|
|
|
|
'show'=>TRUE,
|
|
|
|
'notes'=>'File area for testing',
|
|
|
|
'domain_id'=>$ao->zone->domain_id,
|
|
|
|
'security'=>1,
|
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
2021-07-15 14:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function hierarchy(Domain $domain,int $zoneid)
|
|
|
|
{
|
2023-11-21 23:40:15 +00:00
|
|
|
$hosts = [1,2,3,4,5];
|
|
|
|
$hubs = [10,20,30,40,50];
|
|
|
|
$nodes = [100,200,300,400,500];
|
|
|
|
$hubnodes = [-2,-1,+1,+2,+3];
|
2021-07-15 14:54:23 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
$so = $this->system(sprintf('ZC %s-%s',$domain->name,$zoneid));
|
2021-07-15 14:54:23 +00:00
|
|
|
DB::table('zones')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zoneid,
|
|
|
|
'active'=>TRUE,
|
2023-11-21 23:40:15 +00:00
|
|
|
'default'=>$domain->name === 'a',
|
2021-07-15 14:54:23 +00:00
|
|
|
'notes'=>sprintf('Zone: %03d:0/0.0@%s',$zoneid,$domain->name),
|
|
|
|
'domain_id'=>$domain->id,
|
|
|
|
'system_id'=>$so->id,
|
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$zo = Zone::where('zone_id',$zoneid)->where('domain_id',$domain->id)->singleOrFail();
|
2022-11-19 13:19:09 +00:00
|
|
|
if (self::DEBUG)
|
|
|
|
dump(['zo'=>$zo->zone_id,'rid'=>0,'hid'=>0,'nid'=>0]);
|
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
// ZC
|
2021-07-26 11:21:58 +00:00
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
2023-11-21 23:40:15 +00:00
|
|
|
'validated'=>TRUE,
|
2021-07-26 11:21:58 +00:00
|
|
|
'region_id'=>0,
|
|
|
|
'host_id'=>0,
|
|
|
|
'node_id'=>0,
|
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
2022-01-24 11:56:13 +00:00
|
|
|
'role'=>Address::NODE_ZC,
|
2021-07-26 11:21:58 +00:00
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
2021-07-15 14:54:23 +00:00
|
|
|
|
2022-11-19 13:19:09 +00:00
|
|
|
// ZC Nodes
|
2021-07-15 14:54:23 +00:00
|
|
|
foreach ($nodes as $nid) {
|
2022-11-19 13:19:09 +00:00
|
|
|
if (self::DEBUG)
|
|
|
|
dump(['rid'=>$zo->zone_id,'hid'=>$zo->zone_id,'nid'=>$nid]);
|
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
$so = $this->system(sprintf('ZC Node 0/%d',$nid));
|
2021-07-15 14:54:23 +00:00
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
2023-11-21 23:40:15 +00:00
|
|
|
'validated'=>TRUE,
|
2021-07-15 14:54:23 +00:00
|
|
|
'region_id'=>0,
|
|
|
|
'host_id'=>0,
|
|
|
|
'node_id'=>$nid,
|
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
2022-01-24 11:56:13 +00:00
|
|
|
'role'=>Address::NODE_ACTIVE,
|
2021-07-15 14:54:23 +00:00
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-11-19 13:19:09 +00:00
|
|
|
if (self::DEBUG)
|
|
|
|
dump(['end'=>'nodes top']);
|
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
// Regions
|
2023-11-21 23:40:15 +00:00
|
|
|
foreach ($hosts as $rid) {
|
2022-11-19 13:19:09 +00:00
|
|
|
$hostid = $rid;
|
|
|
|
if (self::DEBUG)
|
|
|
|
dump(['rid'=>$rid,'hid'=>$hostid,'nid'=>0]);
|
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
$so = $this->system(sprintf('Region %03d:%03d/%03d.0@%s',$zoneid,$rid,0,$domain->name));
|
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
2023-11-21 23:40:15 +00:00
|
|
|
'validated'=>TRUE,
|
2021-07-15 14:54:23 +00:00
|
|
|
'region_id'=>$rid,
|
2022-11-19 13:19:09 +00:00
|
|
|
'host_id'=>$rid,
|
2021-07-15 14:54:23 +00:00
|
|
|
'node_id'=>0,
|
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
2022-01-24 11:56:13 +00:00
|
|
|
'role'=>Address::NODE_RC,
|
2021-07-15 14:54:23 +00:00
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
|
2022-11-19 13:19:09 +00:00
|
|
|
// RC Nodes
|
2021-07-15 14:54:23 +00:00
|
|
|
foreach ($nodes as $nid) {
|
2022-11-19 13:19:09 +00:00
|
|
|
if (self::DEBUG)
|
|
|
|
dump(['rid'=>$rid,'hid'=>$hostid,'nid'=>$nid]);
|
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
$so = $this->system(sprintf('RC Node %d/%d',$rid,$nid));
|
2021-07-15 14:54:23 +00:00
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
2023-11-21 23:40:15 +00:00
|
|
|
'validated'=>TRUE,
|
2021-07-15 14:54:23 +00:00
|
|
|
'region_id'=>$rid,
|
2022-11-19 13:19:09 +00:00
|
|
|
'host_id'=>$rid,
|
2021-07-15 14:54:23 +00:00
|
|
|
'node_id'=>$nid,
|
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
2022-01-24 11:56:13 +00:00
|
|
|
'role'=>Address::NODE_ACTIVE,
|
2021-07-15 14:54:23 +00:00
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
}
|
2023-11-21 23:40:15 +00:00
|
|
|
if (self::DEBUG)
|
|
|
|
dump(['end'=>'NODES regions']);
|
2021-07-15 14:54:23 +00:00
|
|
|
|
|
|
|
// Hosts
|
2023-11-21 23:40:15 +00:00
|
|
|
foreach ($hosts as $rrid) {
|
2022-11-19 13:19:09 +00:00
|
|
|
$hostid = $rid*10+$rrid-1;
|
|
|
|
if (self::DEBUG)
|
|
|
|
dump(['rid'=>$rid,'hid'=>$hostid,'nid'=>0]);
|
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
$so = $this->system(sprintf('Host %d:%d/0 (R%d)',$zoneid,$hostid,$rid));
|
2022-11-19 13:19:09 +00:00
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
2023-11-21 23:40:15 +00:00
|
|
|
'validated'=>TRUE,
|
2021-07-15 14:54:23 +00:00
|
|
|
'region_id'=>$rid,
|
|
|
|
'host_id'=>$hostid,
|
2023-12-11 07:31:38 +00:00
|
|
|
'node_id'=>7,
|
2021-07-15 14:54:23 +00:00
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
2022-01-24 11:56:13 +00:00
|
|
|
'role'=>Address::NODE_NC,
|
2021-07-15 14:54:23 +00:00
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Nodes
|
|
|
|
foreach ($nodes as $nid) {
|
2022-11-19 13:19:09 +00:00
|
|
|
if (self::DEBUG)
|
|
|
|
dump(['rid'=>$rid,'hid'=>$hostid,'nid'=>$nid]);
|
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
$so = $this->system(sprintf('Host Node %d/%d (R%d)',$hostid,$nid,$rid));
|
2021-07-15 14:54:23 +00:00
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
2023-11-21 23:40:15 +00:00
|
|
|
'validated'=>TRUE,
|
2021-07-15 14:54:23 +00:00
|
|
|
'region_id'=>$rid,
|
|
|
|
'host_id'=>$hostid,
|
|
|
|
'node_id'=>$nid,
|
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
2022-01-24 11:56:13 +00:00
|
|
|
'role'=>Address::NODE_ACTIVE,
|
2021-07-15 14:54:23 +00:00
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hubs
|
|
|
|
foreach ($hubs as $bid) {
|
2023-11-21 23:40:15 +00:00
|
|
|
$so = $this->system(sprintf('HUB %d/%d (R%d)',$hostid,$bid,$rid));
|
2021-07-15 14:54:23 +00:00
|
|
|
$hub = new Address;
|
|
|
|
$hub->zone_id = $zo->id;
|
|
|
|
$hub->active = TRUE;
|
|
|
|
$hub->region_id = $rid;
|
|
|
|
$hub->host_id = $hostid;
|
|
|
|
$hub->node_id = $bid;
|
|
|
|
$hub->point_id = 0;
|
|
|
|
$hub->system_id = $so->id;
|
2022-01-24 11:56:13 +00:00
|
|
|
$hub->role = Address::NODE_HC;
|
2021-07-15 14:54:23 +00:00
|
|
|
$hub->created_at = Carbon::now();
|
|
|
|
$hub->updated_at = Carbon::now();
|
|
|
|
$hub->save();
|
|
|
|
|
|
|
|
// Nodes
|
|
|
|
foreach ($hubnodes as $nid) {
|
|
|
|
$nodeid = $bid+$nid;
|
2023-11-21 23:40:15 +00:00
|
|
|
$so = $this->system(sprintf('Hub Node %d/%d (R%d/H%d)',$hostid,$nodeid,$rid,$hub->node_id));
|
2021-07-15 14:54:23 +00:00
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
2023-11-21 23:40:15 +00:00
|
|
|
'validated'=>TRUE,
|
2021-07-15 14:54:23 +00:00
|
|
|
'region_id'=>$rid,
|
|
|
|
'host_id'=>$hostid,
|
|
|
|
'node_id'=>$nodeid,
|
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
|
|
|
'hub_id'=>$hub->id,
|
2022-01-24 11:56:13 +00:00
|
|
|
'role'=>Address::NODE_ACTIVE,
|
2021-07-15 14:54:23 +00:00
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-21 23:40:15 +00:00
|
|
|
if (self::DEBUG)
|
|
|
|
dump(['end'=>'NODES normal']);
|
2021-07-15 14:54:23 +00:00
|
|
|
}
|
2022-11-19 13:19:09 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
if (self::DEBUG)
|
|
|
|
dump(['end'=>'heirarchy']);
|
2021-07-15 14:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function system(string $name): System
|
|
|
|
{
|
|
|
|
$o = new System;
|
|
|
|
$o->name = $name;
|
2023-11-21 23:40:15 +00:00
|
|
|
$o->sysop = 'Sysop:'.$name;
|
|
|
|
$o->location = 'Location:'.$name;
|
2021-07-15 14:54:23 +00:00
|
|
|
$o->active = TRUE;
|
|
|
|
$o->created_at = Carbon::now();
|
|
|
|
$o->updated_at = Carbon::now();
|
|
|
|
$o->save();
|
|
|
|
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
}
|