summaryrefslogtreecommitdiffhomepage
path: root/test/scenario_test
diff options
context:
space:
mode:
Diffstat (limited to 'test/scenario_test')
-rw-r--r--test/scenario_test/docker_control.py74
-rw-r--r--test/scenario_test/quagga-rsconfig.go211
-rw-r--r--test/scenario_test/quagga_access.py7
3 files changed, 287 insertions, 5 deletions
diff --git a/test/scenario_test/docker_control.py b/test/scenario_test/docker_control.py
index 1e528bbf..64446111 100644
--- a/test/scenario_test/docker_control.py
+++ b/test/scenario_test/docker_control.py
@@ -287,6 +287,34 @@ def make_config(quagga_num, go_path, bridge, peer_opts=""):
local(cmd, capture=True)
+def make_config_with_policy(quagga_num, go_path, bridge, peer_opts="", policy_pattern=""):
+ if go_path != "":
+ print "specified go path is [ " + go_path + " ]."
+ if os.path.isdir(go_path):
+ go_path += "/"
+ else:
+ print "specified go path is not used."
+ pwd = local("pwd", capture=True)
+ cmd = go_path + "go run " + pwd + "/quagga-rsconfig.go "+" -p "+ policy_pattern + " -n " + str(quagga_num) + \
+ " -c /tmp/gobgp -v " + IP_VERSION + " -i " + bridge["BRIDGE_NAME"][-1] + " " + peer_opts
+ local(cmd, capture=True)
+
+
+def update_policy_config(go_path, policy_pattern=""):
+ if go_path != "":
+ print "specified go path is [ " + go_path + " ]."
+ if os.path.isdir(go_path):
+ go_path += "/"
+ else:
+ print "specified go path is not used."
+
+ pwd = local("pwd", capture=True)
+ cmd = go_path + "go run " + pwd + "/quagga-rsconfig.go --update-policy "+" -p "+ policy_pattern + \
+ " -c /tmp/gobgp "
+ local(cmd, capture=True)
+ reload_config()
+
+
def make_config_append(quagga_num, go_path, bridge, peer_opts=""):
if go_path != "":
print "specified go path is [ " + go_path + " ]."
@@ -357,6 +385,52 @@ def init_test_env_executor(quagga_num, use_local, go_path, log_debug=False, is_r
print "complete initialization of test environment."
+def init_policy_test_env_executor(quagga_num, use_local, go_path, log_debug=False, policy=""):
+ print "start initialization of test environment."
+
+ if docker_container_check() or bridge_setting_check():
+ print "gobgp test environment already exists."
+ print "so that remake gobgp test environment."
+ docker_containers_destroy()
+
+ print "make gobgp policy test environment."
+ create_config_dir()
+ bridge_setting_for_docker_connection(BRIDGES)
+ make_config_with_policy(quagga_num, go_path, BRIDGE_0, policy_pattern=policy)
+
+ # run gobgp docker container
+ docker_container_run_gobgp(BRIDGE_0)
+
+ # set log option
+ opt = "-l debug" if log_debug else ""
+
+ # execute local gobgp program in the docker container if the input option is local
+ if use_local:
+ print "execute gobgp program in local machine."
+ pwd = local("pwd", capture=True)
+ if A_PART_OF_CURRENT_DIR in pwd:
+ gobgp_path = re.sub(A_PART_OF_CURRENT_DIR, "", pwd)
+ cmd = "cp -r " + gobgp_path + " " + CONFIG_DIRR
+ local(cmd, capture=True)
+ make_startup_file_use_local_gobgp(log_opt=opt)
+ else:
+ print "scenario_test directory is not."
+ print "execute gobgp program of osrg/master in github."
+ make_startup_file(log_opt=opt)
+ else:
+ print "execute gobgp program of osrg/master in github."
+ make_startup_file(log_opt=opt)
+
+ change_owner_to_root(CONFIG_DIR)
+ start_gobgp()
+
+ # run quagga docker container
+ for num in range(1, quagga_num + 1):
+ docker_container_run_quagga(num, BRIDGE_0)
+
+ print "complete initialization of test environment."
+
+
def init_ipv6_test_env_executor(quagga_num, use_local, go_path, log_debug=False):
print "start initialization of test environment."
diff --git a/test/scenario_test/quagga-rsconfig.go b/test/scenario_test/quagga-rsconfig.go
index 9f9592d3..2f64ce7b 100644
--- a/test/scenario_test/quagga-rsconfig.go
+++ b/test/scenario_test/quagga-rsconfig.go
@@ -88,7 +88,7 @@ func (qt *QuaggaConfig) IPv6Config() *bytes.Buffer {
return buf
}
-func create_config_files(nr int, outputDir string, IPVersion string, nonePeer bool, normalBGP bool) {
+func create_config_files(nr int, outputDir string, IPVersion string, nonePeer bool, normalBGP bool, policyPattern string) {
quaggaConfigList := make([]*QuaggaConfig, 0)
gobgpConf := config.Bgp{
@@ -98,6 +98,11 @@ func create_config_files(nr int, outputDir string, IPVersion string, nonePeer bo
},
}
+ var binding *PolicyBinding
+ if policyPattern != "" {
+ binding = bindPolicy(policyPattern)
+ }
+
for i := 1; i < nr+1; i++ {
c := config.Neighbor{
PeerAs: 65000 + uint32(i),
@@ -108,6 +113,19 @@ func create_config_files(nr int, outputDir string, IPVersion string, nonePeer bo
Timers: config.Timers{HoldTime: 30, KeepaliveInterval: 10, IdleHoldTimeAfterReset: 10},
PeerType: config.PEER_TYPE_EXTERNAL,
}
+
+ if binding != nil {
+
+ if binding.NeighborAddress == c.NeighborAddress.String() {
+ ap := config.ApplyPolicy{
+ ImportPolicies: binding.ImportPolicyNames,
+ ExportPolicies: binding.ExportPolicyNames,
+ }
+ c.ApplyPolicy = ap
+ }
+
+ }
+
gobgpConf.NeighborList = append(gobgpConf.NeighborList, c)
if !nonePeer {
q := NewQuaggaConfig(i, &gobgpConf.Global, &c, net.ParseIP(serverAddress[IPVersion]))
@@ -128,6 +146,9 @@ func create_config_files(nr int, outputDir string, IPVersion string, nonePeer bo
var buffer bytes.Buffer
encoder := toml.NewEncoder(&buffer)
encoder.Encode(gobgpConf)
+ if binding != nil {
+ encoder.Encode(binding.Policy)
+ }
err := ioutil.WriteFile(fmt.Sprintf("%s/gobgpd.conf", outputDir), buffer.Bytes(), 0644)
if err != nil {
@@ -180,6 +201,180 @@ func append_config_files(ar int, outputDir string, IPVersion string, nonePeer bo
}
}
+func createPolicyConfig() *config.RoutingPolicy {
+
+ ps0 := config.PrefixSet{
+ PrefixSetName: "ps0",
+ PrefixList: []config.Prefix{
+ config.Prefix{
+ Address: net.ParseIP("192.168.0.0"),
+ Masklength: 16,
+ MasklengthRange: "16..24",
+ }},
+ }
+
+ ps1 := config.PrefixSet{
+ PrefixSetName: "ps1",
+ PrefixList: []config.Prefix{
+ config.Prefix{
+ Address: net.ParseIP("192.168.20.0"),
+ Masklength: 24,
+ }, config.Prefix{
+ Address: net.ParseIP("192.168.200.0"),
+ Masklength: 24,
+ }},
+ }
+
+ ps2 := config.PrefixSet{
+ PrefixSetName: "ps2",
+ PrefixList: []config.Prefix{
+ config.Prefix{
+ Address: net.ParseIP("192.168.20.0"),
+ Masklength: 24,
+ }},
+ }
+
+ ns0 := config.NeighborSet{
+ NeighborSetName: "ns0",
+ NeighborInfoList: []config.NeighborInfo{
+ config.NeighborInfo{
+ Address: net.ParseIP("10.0.0.2"),
+ }},
+ }
+
+ ds := config.DefinedSets{
+ PrefixSetList: []config.PrefixSet{ps0, ps1, ps2},
+ NeighborSetList: []config.NeighborSet{ns0},
+ }
+
+ st0 := config.Statement{
+ Name: "st0",
+ Conditions: config.Conditions{
+ MatchPrefixSet: "ps0",
+ MatchNeighborSet: "ns0",
+ MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
+ },
+ Actions: config.Actions{
+ AcceptRoute: false,
+ RejectRoute: true,
+ },
+ }
+
+ st1 := config.Statement{
+ Name: "st1",
+ Conditions: config.Conditions{
+ MatchPrefixSet: "ps1",
+ MatchNeighborSet: "ns0",
+ MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
+ },
+ Actions: config.Actions{
+ AcceptRoute: false,
+ RejectRoute: true,
+ },
+ }
+
+ pd0 := config.PolicyDefinition{
+ Name: "policy0",
+ StatementList: []config.Statement{st0},
+ }
+
+ pd1 := config.PolicyDefinition{
+ Name: "policy1",
+ StatementList: []config.Statement{st1},
+ }
+
+ p := &config.RoutingPolicy{
+ DefinedSets: ds,
+ PolicyDefinitionList: []config.PolicyDefinition{pd0, pd1},
+ }
+ return p
+}
+
+func updatePolicyConfig(outputDir string, pattern string) {
+
+ newConf := config.Bgp{}
+ policyConf := config.RoutingPolicy{}
+
+ _, d_err := toml.DecodeFile(fmt.Sprintf("%s/gobgpd.conf", outputDir), &newConf)
+ if d_err != nil {
+ log.Fatal(d_err)
+ }
+ _, d_err = toml.DecodeFile(fmt.Sprintf("%s/gobgpd.conf", outputDir), &policyConf)
+ if d_err != nil {
+ log.Fatal(d_err)
+ }
+
+ fmt.Println(policyConf)
+
+ st2 := config.Statement{
+ Name: "st2",
+ Conditions: config.Conditions{
+ MatchPrefixSet: "ps2",
+ MatchNeighborSet: "ns0",
+ MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
+ },
+ Actions: config.Actions{
+ AcceptRoute: false,
+ RejectRoute: true,
+ },
+ }
+
+ if pattern == "p3" || pattern == "p4" {
+ policyConf.PolicyDefinitionList[1].StatementList = []config.Statement{st2}
+ }
+
+ var buffer bytes.Buffer
+ encoder := toml.NewEncoder(&buffer)
+ encoder.Encode(newConf)
+ encoder.Encode(policyConf)
+ e_err := ioutil.WriteFile(fmt.Sprintf("%s/gobgpd.conf", outputDir), buffer.Bytes(), 0644)
+ if e_err != nil {
+ log.Fatal(e_err)
+ }
+
+ return
+}
+
+type PolicyBinding struct {
+ NeighborAddress string
+ Policy *config.RoutingPolicy
+ ImportPolicyNames []string
+ ExportPolicyNames []string
+}
+
+func bindPolicy(pattern string) *PolicyBinding {
+
+ var pb *PolicyBinding = &PolicyBinding{Policy: createPolicyConfig()}
+
+ switch pattern {
+ case "p1":
+ pb.NeighborAddress = "10.0.0.3"
+ pb.ImportPolicyNames = []string{"policy0"}
+ pb.ExportPolicyNames = nil
+
+ case "p2":
+ pb.NeighborAddress = "10.0.0.3"
+ pb.ImportPolicyNames = nil
+ pb.ExportPolicyNames = []string{"policy0"}
+
+ case "p3":
+ pb.NeighborAddress = "10.0.0.3"
+ pb.ImportPolicyNames = []string{"policy1"}
+ pb.ExportPolicyNames = nil
+
+ case "p4":
+ pb.NeighborAddress = "10.0.0.3"
+ pb.ImportPolicyNames = nil
+ pb.ExportPolicyNames = []string{"policy1"}
+
+ default:
+ pb = nil
+ }
+
+ return pb
+
+}
+
func main() {
var opts struct {
ClientNumber int `short:"n" long:"client-number" description:"specfying the number of clients" default:"8"`
@@ -189,6 +384,8 @@ func main() {
NetIdentifier int `short:"i" long:"net-identifer" description:"specifing the use network identifier" default:"0"`
NonePeer bool `long:"none-peer" description:"disable make quagga config"`
NormalBGP bool `long:"normal-bgp" description:"generate normal bgp server configuration"`
+ PolicyPattern string `short:"p" long:"policy-pattern" description:"specify policy pattern" default:""`
+ UpdatePolicy bool `long:"update-policy" description:"update exsisting policy config" default:"false"`
}
parser := flags.NewParser(&opts, flags.Default)
_, err := parser.Parse()
@@ -217,12 +414,18 @@ func main() {
baseNeighborNetMask[IPv4] = ".0/24"
}
- if opts.AppendClient == 0 {
- create_config_files(opts.ClientNumber, opts.OutputDir, opts.IPVersion, opts.NonePeer, opts.NormalBGP)
+ isCreateMode := opts.AppendClient == 0 && !opts.UpdatePolicy
+
+ if isCreateMode {
+ create_config_files(opts.ClientNumber, opts.OutputDir, opts.IPVersion, opts.NonePeer, opts.NormalBGP, opts.PolicyPattern)
} else {
if _, err := os.Stat(fmt.Sprintf("%s/gobgpd.conf", opts.OutputDir)); os.IsNotExist(err) {
log.Fatal(err)
}
- append_config_files(opts.AppendClient, opts.OutputDir, opts.IPVersion, opts.NonePeer, opts.NormalBGP)
+ if opts.UpdatePolicy {
+ updatePolicyConfig(opts.OutputDir, opts.PolicyPattern)
+ } else {
+ append_config_files(opts.AppendClient, opts.OutputDir, opts.IPVersion, opts.NonePeer, opts.NormalBGP)
+ }
}
}
diff --git a/test/scenario_test/quagga_access.py b/test/scenario_test/quagga_access.py
index dc77ca07..a42e5eab 100644
--- a/test/scenario_test/quagga_access.py
+++ b/test/scenario_test/quagga_access.py
@@ -30,6 +30,11 @@ def login(host):
return tn
+def logout(tn):
+ tn.write("exit\n")
+ tn.read_all()
+
+
def add_neighbor(tn, as_number, neighbor_address, remote_as):
tn.write("configure terminal\n")
tn.write("router bgp "+str(as_number)+"\n")
@@ -55,7 +60,7 @@ def add_network(tn, as_number, network):
tn.write("network "+ network + " \n")
tn.write("exit\n")
tn.write("exit\n")
- print tn.read_until("bgpd#")
+ tn.read_until("bgpd#")
def add_metric(tn, metric, network):