8000 Added comments to the code and removed commented code · moby/moby@603009c · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 603009c

Browse files
committed
Added comments to the code and removed commented code
1 parent 967c460 commit 603009c

File tree

4 files changed

+33
-74
lines changed

4 files changed

+33
-74
lines changed

vendor/src/github.com/docker/libcontainer/netlink/netlink_linux.go

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,8 @@ func ChangeName(iface *net.Interface, newName string) error {
13091309
return nil
13101310
}
13111311

1312+
// This method is used to add a TBF to container's veth interface in the container's namespace.
1313+
// This classless qdisc is used to shape and limit the rate at which traffic is sent out by a container.
13121314
func SetContainerBandwidth(iface *net.Interface, NetBandwidth int) error {
13131315
NetBand := fmt.Sprintf("%dkbps",NetBandwidth)
13141316
burst := fmt.Sprintf("%dkb",NetBandwidth/10)
@@ -1317,75 +1319,55 @@ func SetContainerBandwidth(iface *net.Interface, NetBandwidth int) error {
13171319
if err != nil{
13181320
fmt.Printf("Error while LookPath command!!!!!!!!")
13191321
}
1320-
//sudo tc qdisc add dev eth0 root tbf rate 10000kbps burst 1000kb latency 70ms mtu 1540
13211322

1322-
//out, er := exec.Command(tcbinary, "qdisc", "add", "dev", iface.Name, "root", "handle", "10:", "htb").Output()
13231323
out, er := exec.Command(tcbinary, "qdisc", "add", "dev", iface.Name, "root", "tbf", "rate", NetBand, "burst", burst, "latency", "70ms", "mtu", "1540").Output()
13241324

13251325
if er != nil{
13261326
fmt.Printf("Error while executing command!!!!!!!!")
13271327
fmt.Println(er)
13281328
fmt.Printf("%s\n",out)
13291329
}
1330-
/*
1331-
outcls, ercls := exec.Command(tcbinary,"class","add","dev",iface.Name,"parent","10:","classid","10:1","htb", "rate", NetBand ).Output()
1332-
1333-
if ercls != nil{
1334-
fmt.Printf("Error while adding tc class!!")
1335-
fmt.Println(ercls)
1336-
fmt.Printf("%s\n",outcls)
1337-
}
1338-
//sudo tc filter add dev eth0 parent 10: protocol ip prio 1 u32 match ip src 0.0.0.0/0
1339-
outfltr, erfltr := exec.Command(tcbinary,"filter","add","dev",iface.Name,"parent","10:","protocol","ip","prio","1","handle", "1:", "cgroup").Output()
1340-
//outfltr, erfltr := exec.Command(tcbinary,"filter","add","dev",iface.Name,"parent","10:","protocol","ip","prio","1","u32", "match", "ip", "src", "0.0.0.0/0").Output()
1341-
1342-
if erfltr != nil{
1343-
fmt.Printf("Error while adding tc filter!!")
1344-
fmt.Println(erfltr)
1345-
fmt.Printf("%s\n",outfltr)
1346-
} */
1330+
13471331
return nil
13481332
}
13491333

1350-
/*
1351-
sudo tc qdisc del dev $DEV root
1352-
sudo tc qdisc add dev $DEV root handle 1: tbf rate 100mbps burst 1600 limit 1
1353-
sudo tc qdisc add dev $DEV parent 1:1 handle 2: prio bands 3
1354-
sudo tc qdisc add dev $DEV parent 2:1 handle 10: sfq perturb 20
1355-
sudo tc qdisc add dev $DEV parent 2:2 handle 20: sfq perturb 20
1356-
sudo tc qdisc add dev $DEV parent 2:3 handle 30: sfq perturb 20
1357-
*/
1334+
// This method is called to install a priority queue TC Prio on docker0
13581335
func InstallPriorityQueue() error {
1359-
fmt.Println("Installing TBF and PRIO queu")
1336+
1337+
// Find the path of TC binary
13601338
tcbinary, err := exec.LookPath("tc")
13611339
if err != nil{
13621340
fmt.Printf("Error while LookPath command!!!!!!!!")
13631341
}
13641342

1343+
// Delete any previously installed qdisc on docker0
13651344
_, errDel := exec.Command(tcbinary, "qdisc", "del", "dev", "docker0", "root").Output()
13661345
if errDel != nil{
13671346
fmt.Printf("Error while deleting priority queue")
13681347
}
13691348

1349+
// Install a classless TBF qdisc, which becomes parent to PRIO qdisc.
1350+
// Having TBF as a parent qdisc helps in bandwidth sharing
13701351
_, errTBF := exec.Command(tcbinary, "qdisc", "add", "dev", "docker0", "root", "handle", "1:", "tbf", "rate", "100mbps", "burst", "1600", "limit", "1").Output()
13711352
if errTBF != nil{
13721353
fmt.Printf("Error while installing tbf queue")
13731354
}
13741355

1356+
// Install classful PRIO qdisc with default 3 classes/bands
13751357
_, errPrio := exec.Command(tcbinary, "qdisc", "add", "dev", "docker0", "parent", "1:1", "handle", "2:", "prio", "bands", "3").Output()
13761358
if errPrio != nil{
13771359
fmt.Printf("Error while installing priority queue")
13781360
}
1379-
1380-
//var er error
1361+
1362+
// Install SFQ qdisc on each of the classes of PRIO qdisc.
13811363
for i:=1; i<4; i++{
13821364
_, _ = exec.Command(tcbinary, "qdisc", "add", "dev", "docker0", "parent", fmt.Sprintf("2:%d",i), "handle", fmt.Sprintf("%d:",i*10), "sfq", "perturb", "20").Output()
13831365
}
13841366

13851367
return nil
13861368
}
13871369

1388-
//sudo tc filter add dev $DEV protocol ip parent 2:0 prio 1 u32 match ip dst 172.17.0.13/32 flowid 2:1
1370+
// This method is called to add a filter rule to TC prio qdisc based on the IP address of a container.
13891371
func ContainerNetworkPriority(netPrio string, IPAddress string ) error{
13901372

13911373
IP := strings.Replace(IPAddress,"/16","/32", 1)
@@ -1408,8 +1390,6 @@ func ContainerNetworkPriority(netPrio string, IPAddress string ) error{
14081390
}
14091391

14101392
_, _ = exec.Command(tcbinary, "filter", "add", "dev", "docker0", "protocol","ip","parent", "2:0", "prio","1", "u32", "match", "ip", "dst", IP, "flowid", fmt.Sprintf("2:%d",containerPriority)).Output()
1411-
1412-
// _, _ = exec.Command(tcbinary, "filter", "add", "dev", "docker0", "protocol","ip","parent", "2:0", "prio","1", "u32", "match", "ip", "src", IP, "flowid", fmt.Sprintf("2:%d",containerPriority)).Output()
14131393

14141394
return nil
14151395
}

vendor/src/github.com/docker/libcontainer/netlink/netlink_linux.go~

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,7 @@ func ChangeName(iface *net.Interface, newName string) error {
13091309
return nil
13101310
}
13111311

1312+
// This method is used to add a TBF to container's veth interface in the container's namespace.
13121313
func SetContainerBandwidth(iface *net.Interface, NetBandwidth int) error {
13131314
NetBand := fmt.Sprintf("%dkbps",NetBandwidth)
13141315
burst := fmt.Sprintf("%dkb",NetBandwidth/10)
@@ -1317,75 +1318,55 @@ func SetContainerBandwidth(iface *net.Interface, NetBandwidth int) error {
13171318
if err != nil{
13181319
fmt.Printf("Error while LookPath command!!!!!!!!")
13191320
}
1320-
//sudo tc qdisc add dev eth0 root tbf rate 10000kbps burst 1000kb latency 70ms mtu 1540
13211321

1322-
//out, er := exec.Command(tcbinary, "qdisc", "add", "dev", iface.Name, "root", "handle", "10:", "htb").Output()
13231322
out, er := exec.Command(tcbinary, "qdisc", "add", "dev", iface.Name, "root", "tbf", "rate", NetBand, "burst", burst, "latency", "70ms", "mtu", "1540").Output()
13241323

13251324
if er != nil{
13261325
fmt.Printf("Error while executing command!!!!!!!!")
13271326
fmt.Println(er)
13281327
fmt.Printf("%s\n",out)
13291328
}
1330-
/*
1331-
outcls, ercls := exec.Command(tcbinary,"class","add","dev",iface.Name,"parent","10:","classid","10:1","htb", "rate", NetBand ).Output()
1332-
1333-
if ercls != nil{
1334-
fmt.Printf("Error while adding tc class!!")
1335-
fmt.Println(ercls)
1336-
fmt.Printf("%s\n",outcls)
1337-
}
1338-
//sudo tc filter add dev eth0 parent 10: protocol ip prio 1 u32 match ip src 0.0.0.0/0
1339-
outfltr, erfltr := exec.Command(tcbinary,"filter","add","dev",iface.Name,"parent","10:","protocol","ip","prio","1","handle", "1:", "cgroup").Output()
1340-
//outfltr, erfltr := exec.Command(tcbinary,"filter","add","dev",iface.Name,"parent","10:","protocol","ip","prio","1","u32", "match", "ip", "src", "0.0.0.0/0").Output()
1341-
1342-
if erfltr != nil{
1343-
fmt.Printf("Error while adding tc filter!!")
1344-
fmt.Println(erfltr)
1345-
fmt.Printf("%s\n",outfltr)
1346-
} */
1329+
13471330
return nil
13481331
}
13491332

1350-
/*
1351-
sudo tc qdisc del dev $DEV root
1352-
sudo tc qdisc add dev $DEV root handle 1: tbf rate 100mbps burst 1600 limit 1
1353-
sudo tc qdisc add dev $DEV parent 1:1 handle 2: prio bands 3
1354-
sudo tc qdisc add dev $DEV parent 2:1 handle 10: sfq perturb 20
1355-
sudo tc qdisc add dev $DEV parent 2:2 handle 20: sfq perturb 20
1356-
sudo tc qdisc add dev $DEV parent 2:3 handle 30: sfq perturb 20
1357-
*/
1333+
// This method is called to install a priority queue TC Prio on docker0
13581334
func InstallPriorityQueue() error {
1359-
fmt.Println("Installing TBF and PRIO queu")
1335+
1336+
// Find the path of TC binary
13601337
tcbinary, err := exec.LookPath("tc")
13611338
if err != nil{
13621339
fmt.Printf("Error while LookPath command!!!!!!!!")
13631340
}
13641341

1342+
// Delete any previously installed qdisc on docker0
13651343
_, errDel := exec.Command(tcbinary, "qdisc", "del", "dev", "docker0", "root").Output()
13661344
if errDel != nil{
13671345
fmt.Printf("Error while deleting priority queue")
13681346
}
13691347

1348+
// Install a classless TBF qdisc, which becomes parent to PRIO qdisc.
1349+
// Having TBF as a parent qdisc helps in bandwidth sharing
13701350
_, errTBF := exec.Command(tcbinary, "qdisc", "add", "dev", "docker0", "root", "handle", "1:", "tbf", "rate", "100mbps", "burst", "1600", "limit", "1").Output()
13711351
if errTBF != nil{
13721352
fmt.Printf("Error while installing tbf queue")
13731353
}
13741354

1355+
// Install classful PRIO qdisc with default 3 classes/bands
13751356
_, errPrio := exec.Command(tcbinary, "qdisc", "add", "dev", "docker0", "parent", "1:1", "handle", "2:", "prio", "bands", "3").Output()
13761357
if errPrio != nil{
13771358
fmt.Printf("Error while installing priority queue")
13781359
}
1379-
1380-
//var er error
1360+
1361+
// Install SFQ qdisc on each of the classes of PRIO qdisc.
13811362
for i:=1; i<4; i++{
13821363
_, _ = exec.Command(tcbinary, "qdisc", "add", "dev", "docker0", "parent", fmt.Sprintf("2:%d",i), "handle", fmt.Sprintf("%d:",i*10), "sfq", "perturb", "20").Output()
13831364
}
13841365

13851366
return nil
13861367
}
13871368

1388-
//sudo tc filter add dev $DEV protocol ip parent 2:0 prio 1 u32 match ip dst 172.17.0.13/32 flowid 2:1
1369+
// This method is called to add a filter rule to TC prio qdisc based on the IP address of a container.
13891370
func ContainerNetworkPriority(netPrio string, IPAddress string ) error{
13901371

13911372
IP := strings.Replace(IPAddress,"/16","/32", 1)
@@ -1408,8 +1389,6 @@ func ContainerNetworkPriority(netPrio string, IPAddress string ) error{
14081389
}
14091390

14101391
_, _ = exec.Command(tcbinary, "filter", "add", "dev", "docker0", "protocol","ip","parent", "2:0", "prio","1", "u32", "match", "ip", "dst", IP, "flowid", fmt.Sprintf("2:%d",containerPriority)).Output()
1411-
1412-
_, _ = exec.Command(tcbinary, "filter", "add", "dev", "docker0", "protocol","ip","parent", "2:0", "prio","1", "u32", "match", "ip", "src", IP, "flowid", fmt.Sprintf("2:%d",containerPriority)).Output()
14131392

14141393
return nil
14151394
}

vendor/src/github.com/docker/libcontainer/network_linux.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,17 @@ func (v *veth) create(n *network, nspid int) (err error) {
146146
if err != nil {
147147
return err
148148
}
149-
149+
// Flag installPrioQueue is checked to install TC PRIO queue.
150+
// The qdisc needs to be installed only once
150151
if installPrioQueue {
151152
if err := netlink.InstallPriorityQueue(); err != nil {
152153
return err
153154
}
154155
installPrioQueue = false
155156
}
156-
157+
158+
// This method is called to add a filter to the qdisc based on the IP address.
159+
// Adding a rule will assign priority to the packets and hence to the containers.
157160
if err := netlink.ContainerNetworkPriority(n.NetPrio, n.Address); err != nil {
158161
return err
159162
}
@@ -167,8 +170,6 @@ func (v *veth) generateTempPeerName() (string, error) {
167170
}
168171

169172
func (v *veth) initialize(config *network) error {
170-
//fmt.Println("config.Config.Cgroups.NetPrio=",config.Config.Cgroups.NetPrio)
171-
//fmt.Println("configNet.NetBandwidth=",configNet.NetBandwidth)
172173
peer := config.TempVethPeerName
173174
if peer == "" {
174175
return fmt.Errorf("peer is not specified")

vendor/src/github.com/docker/libcontainer/network_linux.go~

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ func (v *veth) create(n *network, nspid int) (err error) {
146146
if err != nil {
147147
return err
148148
}
149-
149+
// Flag installPrioQueue is checked to install TC PRIO queue.
150+
// The qdisc needs to be installed only once
150151
if installPrioQueue {
151152
if err := netlink.InstallPriorityQueue(); err != nil {
152153
return err
@@ -167,8 +168,6 @@ func (v *veth) generateTempPeerName() (string, error) {
167168
}
168169

169170
func (v *veth) initialize(config *network) error {
170-
//fmt.Println("config.Config.Cgroups.NetPrio=",config.Config.Cgroups.NetPrio)
171-
//fmt.Println("configNet.NetBandwidth=",configNet.NetBandwidth)
172171
peer := config.TempVethPeerName
173172
if peer == "" {
174173
return fmt.Errorf("peer is not specified")
@@ -207,7 +206,7 @@ func (v *veth) initialize(config *network) error {
207206
return err
208207
}
209208
}
210-
if err := netlink.NetworkSetMTU(child, configNet.Mtu); err != nil {
209+
if err := netlink.NetworkSetMTU(child, config.Mtu); err != nil {
211210
return err
212211
}
213212
if err := netlink.NetworkLinkUp(child); err != nil {

0 commit comments

Comments
 (0)
0