Skip to content

Commit

Permalink
Merge pull request #25 from gcetusic/development
Browse files Browse the repository at this point in the history
Development - no bridges for l3node links
  • Loading branch information
oikuda committed Jun 23, 2015
2 parents b0a8136 + f2738b1 commit 37eeda3
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 43 deletions.
54 changes: 27 additions & 27 deletions config/linkcfg.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
# NAME
# linkcfg.tcl -- file used for manipultaion with links in IMUNES
# FUNCTION
# This module is used to define all the actions used for configuring
# links in IMUNES.
# This module is used to define all the actions used for configuring
# links in IMUNES.
#
# NOTES
#
#
# linkPeers { link }
# Returns nodes of link endpoints
#
Expand All @@ -51,7 +51,7 @@
# ... in bits per second
#
# getLinkBandwidthString { link }
# ... as string
# ... as string
#
# getLinkDelay { link }
# ... in microseconds
Expand Down Expand Up @@ -121,8 +121,8 @@ proc linkByPeers { node1 node2 } {
# SYNOPSIS
# removeLink $link
# FUNCTION
# Removes the link and related entries in peering node's configs.
# Updates the default route for peer nodes.
# Removes the link and related entries in peering node's configs.
# Updates the default route for peer nodes.
# INPUTS
# * link -- link id
#****
Expand All @@ -140,12 +140,12 @@ proc removeLink { link } {
set i [lsearch $pnodes $node]
set peer [lreplace $pnodes $i $i]
set ifc [ifcByPeer $node $peer]
set index [lsearch -exact $IPv4UsedList [getIfcIPv4addr $node $ifc]]
set IPv4UsedList [lreplace $IPv4UsedList $index $index]
set index [lsearch -exact $IPv6UsedList [getIfcIPv6addr $node $ifc]]
set IPv6UsedList [lreplace $IPv6UsedList $index $index]
set index [lsearch -exact $MACUsedList [getIfcMACaddr $node $ifc]]
set MACUsedList [lreplace $MACUsedList $index $index]
set index [lsearch -exact $IPv4UsedList [getIfcIPv4addr $node $ifc]]
set IPv4UsedList [lreplace $IPv4UsedList $index $index]
set index [lsearch -exact $IPv6UsedList [getIfcIPv6addr $node $ifc]]
set IPv6UsedList [lreplace $IPv6UsedList $index $index]
set index [lsearch -exact $MACUsedList [getIfcMACaddr $node $ifc]]
set MACUsedList [lreplace $MACUsedList $index $index]
netconfClearSection $node "interface $ifc"
set i [lsearch [set $node] "interface-peer {$ifc $peer}"]
set $node [lreplace [set $node] $i $i]
Expand All @@ -159,7 +159,7 @@ proc removeLink { link } {
switch -exact [getLogIfcType $node $lifc] {
vlan {
if {[getIfcVlanDev $node $lifc] == $ifc} {
netconfClearSection $node "interface $lifc"
netconfClearSection $node "interface $lifc"
}
}
}
Expand Down Expand Up @@ -281,7 +281,7 @@ proc getLinkColor { link } {
# SYNOPSIS
# setLinkColor $link $value
# FUNCTION
# Sets the color of the link.
# Sets the color of the link.
# INPUTS
# * link -- link id
# * value -- link color
Expand Down Expand Up @@ -690,7 +690,7 @@ proc setLinkBER { link value } {

#****f* linkcfg.tcl/getLinkDup
# NAME
# getLinkDup -- get link packet duplicate value
# getLinkDup -- get link packet duplicate value
# SYNOPSIS
# set duplicate [getLinkDup $link]
# FUNCTION
Expand All @@ -709,7 +709,7 @@ proc getLinkDup { link } {

#****f* linkcfg.tcl/setLinkDup
# NAME
# setLinkDup -- set link packet duplicate value
# setLinkDup -- set link packet duplicate value
# SYNOPSIS
# setLinkDup $link $value
# FUNCTION
Expand All @@ -731,7 +731,7 @@ proc setLinkDup { link value } {

#****f* linkcfg.tcl/linkResetConfig
# NAME
# linkResetConfig -- reset link configuration
# linkResetConfig -- reset link configuration
# SYNOPSIS
# linkResetConfig $link
# FUNCTION
Expand All @@ -742,10 +742,10 @@ proc setLinkDup { link value } {
proc linkResetConfig { link } {
upvar 0 ::cf::[set ::curcfg]::oper_mode oper_mode

setLinkBandwidth $link ""
setLinkBER $link ""
setLinkDelay $link ""
setLinkDup $link ""
setLinkBandwidth $link ""
setLinkBER $link ""
setLinkDelay $link ""
setLinkDup $link ""
if { $oper_mode == "exec" } {
upvar 0 ::cf::[set ::curcfg]::eid eid
execSetLinkParams $eid $link
Expand All @@ -755,7 +755,7 @@ proc linkResetConfig { link } {

#****f* linkcfg.tcl/getLinkMirror
# NAME
# getLinkMirror -- get link's mirror link
# getLinkMirror -- get link's mirror link
# SYNOPSIS
# set mirror_link_id [getLinkMirror $link]
# FUNCTION
Expand All @@ -776,7 +776,7 @@ proc getLinkMirror { link } {

#****f* linkcfg.tcl/setLinkMirror
# NAME
# setLinkMirror -- set link's mirror link
# setLinkMirror -- set link's mirror link
# SYNOPSIS
# setLinkMirror $link $mirror_link_id
# FUNCTION
Expand Down Expand Up @@ -809,7 +809,7 @@ proc setLinkMirror { link value } {
# link.
# INPUTS
# * link -- link id
# * nodetype -- type of the new nodes connecting split links.
# * nodetype -- type of the new nodes connecting split links.
# Usual value is pseudo.
# RESULT
# * nodes -- list of node ids of new nodes.
Expand Down Expand Up @@ -988,7 +988,7 @@ proc newLink { lnode1 lnode2 } {
}
}
}

set link [newObjectId link]
upvar 0 ::cf::[set ::curcfg]::$link $link
set $link {}
Expand Down Expand Up @@ -1027,7 +1027,7 @@ proc newLink { lnode1 lnode2 } {
[nodeType $lnode1].confNewIfc $lnode1 $ifname1
}
}

return $link
}

Expand All @@ -1039,7 +1039,7 @@ proc newLink { lnode1 lnode2 } {
# FUNCTION
# Returns the link id of the link connecting the node's interface.
# INPUTS
# * node -- node id
# * node -- node id
# * ifc -- interface
# RESULT
# * link -- link id.
Expand Down
57 changes: 41 additions & 16 deletions runtime/linux.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ proc prepareFilesystemForNode { node } {
set VROOTDIR /var/imunes
set VROOT_RUNTIME $VROOTDIR/$eid/$node
pipesExec "mkdir -p $VROOT_RUNTIME" "hold"
pipesExec "mkdir -p /var/run/netns" "hold"
}

#XXX-comment
Expand Down Expand Up @@ -339,23 +340,39 @@ proc createLinkBetween { lnode1 lnode2 ifname1 ifname2 } {
if { [[typemodel $lnode2].virtlayer] == "VIMAGE" } {
if {[nodeType $lnode1] == "rj45"} {
set extIfcName [getNodeName $lnode1]
pipework $extIfcName $ifname2 $lnode2 $ether2
addNodeIfcToBridge $extIfcName $ifname2 $lnode2 $ether2
} else {
pipework $lnode1 $ifname2 $lnode2 $ether2
addNodeIfcToBridge $lnode1 $ifname2 $lnode2 $ether2
}
}
} elseif { [[typemodel $lnode1].virtlayer] == "VIMAGE" } {
if { [[typemodel $lnode2].virtlayer] == "VIMAGE" } {
set link [linkByPeers $lnode1 $lnode2]
pipework $link $ifname1 $lnode1 $ether1
pipework $link $ifname2 $lnode2 $ether2
# prepare namespace files
set lnode1Ns [createNetNs $lnode1]
set lnode2Ns [createNetNs $lnode2]
# generate temporary interface names
set hostIfc1 "v${ifname1}pn${lnode1Ns}"
set hostIfc2 "v${ifname2}pn${lnode2Ns}"
# create veth pair
exec ip link add name "$hostIfc1" type veth peer name "$hostIfc2"
# move veth pair sides to node namespaces
setIfcNetNs $lnode1 $hostIfc1 $ifname1
setIfcNetNs $lnode2 $hostIfc2 $ifname2
# set mac addresses of node ifcs
exec ip netns exec "$lnode1Ns" ip link set dev "$ifname1" \
address "$ether1"
exec ip netns exec "$lnode2Ns" ip link set dev "$ifname2" \
address "$ether2"
# remove nodeNs to avoid `ip netns` catching it
exec rm -f "/var/run/netns/$lnode1Ns"
exec rm -f "/var/run/netns/$lnode2Ns"
}
if { [[typemodel $lnode2].virtlayer] == "NETGRAPH" } {
if {[nodeType $lnode2] == "rj45"} {
set extIfcName [getNodeName $lnode2]
pipework $extIfcName $ifname1 $lnode1 $ether1
addNodeIfcToBridge $extIfcName $ifname1 $lnode1 $ether1
} else {
pipework $lnode2 $ifname1 $lnode1 $ether1
addNodeIfcToBridge $lnode2 $ifname1 $lnode1 $ether1
}
}
}
Expand Down Expand Up @@ -693,15 +710,10 @@ proc getNodeNamespace { node } {
return $ns
}

proc pipework { bridge ifc node mac } {
proc addNodeIfcToBridge { bridge ifc node mac } {
upvar 0 ::cf::[set ::curcfg]::eid eid

# prepare namespace files
set nodeNs [getNodeNamespace $node]
exec mkdir -p /var/run/netns
exec rm -f "/var/run/netns/$nodeNs"
exec ln -s "/proc/$nodeNs/ns/net" "/var/run/netns/$nodeNs"

set nodeNs [createNetNs $node]
# create bridge
catch "exec ovs-vsctl add-br $eid.$bridge"

Expand All @@ -716,8 +728,8 @@ proc pipework { bridge ifc node mac } {
exec ip link set "$hostIfc" up

# move guest side of veth pair to node namespace
exec ip link set "$guestIfc" netns "$nodeNs"
exec ip netns exec "$nodeNs" ip link set "$guestIfc" name "$ifc"
setIfcNetNs $node $guestIfc $ifc
# set mac address
exec ip netns exec "$nodeNs" ip link set dev "$ifc" address "$mac"

# remove nodeNs to avoid `ip netns` catching it
Expand All @@ -744,3 +756,16 @@ proc checkSysPrerequisites {} {

return ""
}

proc createNetNs { node } {
set nodeNs [getNodeNamespace $node]
exec rm -f "/var/run/netns/$nodeNs"
exec ln -s "/proc/$nodeNs/ns/net" "/var/run/netns/$nodeNs"
return $nodeNs
}

proc setIfcNetNs { node oldIfc newIfc } {
set nodeNs [getNodeNamespace $node]
exec ip link set "$oldIfc" netns "$nodeNs"
exec ip netns exec "$nodeNs" ip link set "$oldIfc" name "$newIfc"
}

0 comments on commit 37eeda3

Please sign in to comment.