Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
opentrafficshaper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yuriy
opentrafficshaper
Commits
8ee91033
Commit
8ee91033
authored
11 years ago
by
Nigel Kukard
Browse files
Options
Downloads
Patches
Plain Diff
Moved more code out the framework into cfg manager
parent
d027cc2f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
opentrafficshaper/plugins/configmanager.pm
+136
-5
136 additions, 5 deletions
opentrafficshaper/plugins/configmanager.pm
with
136 additions
and
5 deletions
opentrafficshaper/plugins/configmanager.pm
+
136
−
5
View file @
8ee91033
...
@@ -57,6 +57,15 @@ our $pluginInfo = {
...
@@ -57,6 +57,15 @@ our $pluginInfo = {
my
$globals
;
my
$globals
;
my
$logger
;
my
$logger
;
# Config
my
$config
;
my
$groups
=
{
1
=>
'
Default
'
};
my
$classes
=
{
1
=>
'
Default
'
};
# Pending changes
# Pending changes
my
$changeQueue
=
{
};
my
$changeQueue
=
{
};
# UserID counter
# UserID counter
...
@@ -64,6 +73,7 @@ my $userIDMap = {};
...
@@ -64,6 +73,7 @@ my $userIDMap = {};
my
$userIDCounter
=
1
;
my
$userIDCounter
=
1
;
# Initialize plugin
# Initialize plugin
sub
init
sub
init
{
{
...
@@ -83,7 +93,54 @@ sub init
...
@@ -83,7 +93,54 @@ sub init
}
}
);
);
$logger
->
log
(
LOG_NOTICE
,"
[CONFIGMANAGER] OpenTrafficShaper Config Manager v
"
.
VERSION
.
"
- Copyright (c) 2013, AllWorldIT
")
$logger
->
log
(
LOG_NOTICE
,"
[CONFIGMANAGER] OpenTrafficShaper Config Manager v
"
.
VERSION
.
"
- Copyright (c) 2013, AllWorldIT
");
# Split off groups to load
$logger
->
log
(
LOG_DEBUG
,"
[CONFIGMANAGER] Loading traffic groups...
");
# Check if we loaded an array or just text
my
@groups
=
ref
(
$globals
->
{'
file.config
'}
->
{'
shaping
'}
->
{'
group
'})
eq
"
ARRAY
"
?
@
{
$globals
->
{'
file.config
'}
->
{'
shaping
'}
->
{'
group
'}}
:
(
$globals
->
{'
file.config
'}
->
{'
shaping
'}
->
{'
group
'}
);
# Loop with groups
foreach
my
$group
(
@groups
)
{
# Skip comments
next
if
(
$group
=~
/^\s*#/
);
# Split off group ID and group name
my
(
$groupID
,
$groupName
)
=
split
(
/:/
,
$group
);
if
(
!
defined
(
$groupID
)
||
int
(
$groupID
)
<
1
)
{
$logger
->
log
(
LOG_WARN
,"
[CONFIGMANAGER] Failed to load traffic group definition '
$group
': ID is invalid
");
next
;
}
if
(
!
defined
(
$groupName
)
||
$groupName
eq
"")
{
$logger
->
log
(
LOG_WARN
,"
[CONFIGMANAGER] Failed to load traffic group definition '
$group
': Name is invalid
");
next
;
}
$groups
->
{
$groupID
}
=
$groupName
;
$logger
->
log
(
LOG_INFO
,"
[CONFIGMANAGER] Loaded traffic group '
$groupName
' with ID
$groupID
.
");
}
$logger
->
log
(
LOG_DEBUG
,"
[CONFIGMANAGER] Loading traffic groups completed.
");
# Split off traffic classes
$logger
->
log
(
LOG_DEBUG
,"
[CONFIGMANAGER] Loading traffic classes...
");
# Check if we loaded an array or just text
my
@classes
=
ref
(
$globals
->
{'
file.config
'}
->
{'
shaping
'}
->
{'
class
'})
eq
"
ARRAY
"
?
@
{
$globals
->
{'
file.config
'}
->
{'
shaping
'}
->
{'
class
'}}
:
(
$globals
->
{'
file.config
'}
->
{'
shaping
'}
->
{'
class
'}
);
# Loop with classes
foreach
my
$class
(
@classes
)
{
# Skip comments
next
if
(
$class
=~
/^\s*#/
);
# Split off class ID and class name
my
(
$classID
,
$className
)
=
split
(
/:/
,
$class
);
if
(
!
defined
(
$classID
)
||
int
(
$classID
)
<
1
)
{
$logger
->
log
(
LOG_WARN
,"
[CONFIGMANAGER] Failed to load traffic class definition '
$class
': ID is invalid
");
next
;
}
if
(
!
defined
(
$className
)
||
$className
eq
"")
{
$logger
->
log
(
LOG_WARN
,"
[CONFIGMANAGER] Failed to load traffic class definition '
$class
': Name is invalid
");
next
;
}
$classes
->
{
$classID
}
=
$className
;
$logger
->
log
(
LOG_INFO
,"
[CONFIGMANAGER] Loaded traffic class '
$className
' with ID
$classID
.
");
}
$logger
->
log
(
LOG_DEBUG
,"
[CONFIGMANAGER] Loading traffic classes completed.
");
}
}
...
@@ -130,6 +187,8 @@ sub session_tick {
...
@@ -130,6 +187,8 @@ sub session_tick {
# This is now live
# This is now live
$users
->
{
$uid
}
=
$cuser
;
$users
->
{
$uid
}
=
$cuser
;
$users
->
{
$uid
}
->
{'
shaper.live
'}
=
SHAPER_PENDING
;
$users
->
{
$uid
}
->
{'
shaper.live
'}
=
SHAPER_PENDING
;
# Clean things up a bit
# Post to shaper
# Post to shaper
$kernel
->
post
("
shaper
"
=>
"
add
"
=>
$uid
);
$kernel
->
post
("
shaper
"
=>
"
add
"
=>
$uid
);
...
@@ -201,7 +260,31 @@ sub session_tick {
...
@@ -201,7 +260,31 @@ sub session_tick {
};
};
# Read event for server
# Process shaper change
# Supoprted user attributes:
#
# Username
# - Users username
# IP
# - Users IP
# GroupID
# - Group ID
# ClassID
# - Class ID
# TrafficLimitTx
# - Traffic limit in kbps
# TrafficLimitRx
# - Traffic limit in kbps
# TrafficLimitTxBurst
# - Traffic bursting limit in kbps
# TrafficLimitRxBurst
# - Traffic bursting limit in kbps
# Status
# - new
# - offline
# - online
# - unknown
sub
process_change
{
sub
process_change
{
my
(
$kernel
,
$user
)
=
@_
[
KERNEL
,
ARG0
];
my
(
$kernel
,
$user
)
=
@_
[
KERNEL
,
ARG0
];
...
@@ -216,15 +299,63 @@ sub process_change {
...
@@ -216,15 +299,63 @@ sub process_change {
$userIDMap
->
{
$userUniq
}
=
$uid
=
++
$userIDCounter
;
$userIDMap
->
{
$userUniq
}
=
$uid
=
++
$userIDCounter
;
}
}
# We start off blank so we only pull in whats supported
my
$userChange
;
if
(
!
(
$userChange
->
{'
Username
'}
=
$user
->
{'
Username
'}))
{
$logger
->
log
(
LOG_DEBUG
,"
[CONFIGMANAGER] Cannot process user change as username is invalid.
");
}
$userChange
->
{'
Username
'}
=
$user
->
{'
Username
'};
$userChange
->
{'
IP
'}
=
$user
->
{'
IP
'};
# Check group is OK
if
(
!
(
$userChange
->
{'
GroupID
'}
=
checkGroupID
(
$user
->
{'
GroupID
'})))
{
$logger
->
log
(
LOG_DEBUG
,"
[CONFIGMANAGER] Cannot process user change for '
"
.
$user
->
{'
Username
'}
.
"
' as the GroupID is invalid.
");
}
# Check class is OK
if
(
!
(
$userChange
->
{'
ClassID
'}
=
checkClassID
(
$user
->
{'
ClassID
'})))
{
$logger
->
log
(
LOG_DEBUG
,"
[CONFIGMANAGER] Cannot process user change for '
"
.
$user
->
{'
Username
'}
.
"
' as the ClassID is invalid.
");
}
$userChange
->
{'
TrafficLimitTx
'}
=
$user
->
{'
TrafficLimitTx
'};
$userChange
->
{'
TrafficLimitRx
'}
=
$user
->
{'
TrafficLimitRx
'};
# Take base limits if we don't have any burst values set
$userChange
->
{'
TrafficLimitTxBurst
'}
=
defined
(
$user
->
{'
TrafficLimitTxBurst
'})
?
$user
->
{'
TrafficLimitTxBurst
'}
:
$user
->
{'
TrafficLimitTx
'};
$userChange
->
{'
TrafficLimitRxBurst
'}
=
defined
(
$user
->
{'
TrafficLimitRxBurst
'})
?
$user
->
{'
TrafficLimitRxBurst
'}
:
$user
->
{'
TrafficLimitRx
'};
# Check status is OK
if
(
!
(
$userChange
->
{'
Status
'}
=
checkStatus
(
$user
->
{'
Status
'})))
{
$logger
->
log
(
LOG_DEBUG
,"
[CONFIGMANAGER] Cannot process user change for '
"
.
$user
->
{'
Username
'}
.
"
' as the Status is invalid.
");
}
# Set the user ID before we post to the change queue
# Set the user ID before we post to the change queue
$user
->
{'
ID
'}
=
$uid
;
$userChange
->
{'
ID
'}
=
$uid
;
$user
->
{'
LastUpdate
'}
=
time
();
$userChange
->
{'
LastUpdate
'}
=
time
();
# Push change to change queue
# Push change to change queue
$changeQueue
->
{
$uid
}
=
$user
;
$changeQueue
->
{
$uid
}
=
$userChange
;
}
# Function to check the group ID exists
sub
checkGroupID
{
my
$gid
=
shift
;
return
$gid
if
(
defined
(
$groups
->
{
$gid
}));
}
}
# Function to check the class ID exists
sub
checkClassID
{
my
$cid
=
shift
;
return
$cid
if
(
defined
(
$classes
->
{
$cid
}));
}
# Function to check if the status is ok
sub
checkStatus
{
my
$status
=
shift
;
if
(
$status
eq
"
new
"
||
$status
eq
"
offline
"
||
$status
eq
"
online
"
||
$status
eq
"
unknown
")
{
return
$status
}
}
1
;
1
;
# vim: ts=4
# vim: ts=4
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment