Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 14CBE200AE4 for ; Wed, 11 May 2016 00:10:51 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 13771160A11; Tue, 10 May 2016 22:10:51 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 37FBC16098A for ; Wed, 11 May 2016 00:10:50 +0200 (CEST) Received: (qmail 45896 invoked by uid 500); 10 May 2016 22:10:49 -0000 Mailing-List: contact dev-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list dev@cloudstack.apache.org Received: (qmail 45885 invoked by uid 99); 10 May 2016 22:10:49 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 May 2016 22:10:49 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E2693DFE16; Tue, 10 May 2016 22:10:48 +0000 (UTC) From: jburwell To: dev@cloudstack.apache.org Reply-To: dev@cloudstack.apache.org References: In-Reply-To: Subject: [GitHub] cloudstack pull request: OSPF: adding dynamically routing capabili... Content-Type: text/plain Message-Id: <20160510221048.E2693DFE16@git1-us-west.apache.org> Date: Tue, 10 May 2016 22:10:48 +0000 (UTC) archived-at: Tue, 10 May 2016 22:10:51 -0000 Github user jburwell commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/1371#discussion_r62762933 --- Diff: core/src/com/cloud/agent/resource/virtualnetwork/facade/QuaggaConfigItem.java --- @@ -0,0 +1,93 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +package com.cloud.agent.resource.virtualnetwork.facade; + +import java.util.List; + +import com.cloud.agent.api.routing.NetworkElementCommand; +import com.cloud.agent.api.routing.QuaggaConfigCommand; +import com.cloud.agent.resource.virtualnetwork.ConfigItem; +import com.cloud.agent.resource.virtualnetwork.VRScripts; +import com.cloud.agent.resource.virtualnetwork.model.ConfigBase; +import com.cloud.agent.resource.virtualnetwork.model.QuaggaRule; +import com.cloud.network.vpc.OSPFZoneConfig; +import com.cloud.utils.net.cidr.CIDR; + +public class QuaggaConfigItem extends AbstractConfigItemFacade { + + @Override + public List generateConfig(final NetworkElementCommand cmd) { + final QuaggaConfigCommand command = (QuaggaConfigCommand)cmd; + + final String vrIp = command.getRouterPublicIp(); + final String vrName = command.getRouterName(); + final CIDR[] cidrs = command.getTierCidrs(); + final OSPFZoneConfig qzc = command.getZoneConfig(); + + StringBuilder zebra = new StringBuilder(); + zebra.append("hostname " + vrName).append(","); + zebra.append("interface eth1").append(","); + zebra.append(" description link to area 0").append(","); + zebra.append(" ip address " + vrIp + "/24").append(","); + zebra.append(" link-detect").append(","); + zebra.append("log file /var/log/quagga/zebra.log").append(","); + + StringBuilder ospfd = new StringBuilder(); + ospfd.append("hostname " + vrName).append(","); + ospfd.append("interface eth1").append(","); + ospfd.append(" ip ospf hello-interval ").append(qzc.getHelloInterval()).append(","); + ospfd.append(" ip ospf dead-interval ").append(qzc.getDeadInterval()).append(","); + ospfd.append(" ip ospf retransmit-interval ").append(qzc.getRetransmitInterval()).append(","); + ospfd.append(" ip ospf transmit-delay ").append(qzc.getTransitDelay()).append(","); + if (qzc.getAuthentication().equals(OSPFZoneConfig.Authentication.MD5) && qzc.getPassword().length() > 3){ + ospfd.append(" ip ospf authentication message-digest").append(","); + ospfd.append(" ip ospf message-digest-key 1 md5 ").append(qzc.getPassword()).append(","); + } + ospfd.append("router ospf").append(","); + ospfd.append(" ospf router-id " + vrIp).append(","); + ospfd.append(" redistribute connected").append(","); + ospfd.append(" no passive-interface eth1").append(","); + ospfd.append(" network " + vrIp + "/24 area ").append(qzc.getOspfArea()).append(","); + if (qzc.getAuthentication().equals(OSPFZoneConfig.Authentication.MD5) && qzc.getPassword().length() > 3){ + ospfd.append(" area ").append(qzc.getOspfArea()).append(" authentication message-digest").append(","); + } + if (cidrs != null) { + for (CIDR cidr : cidrs) { + ospfd.append(" network " + cidr + " area ").append(qzc.getOspfArea()).append(","); + } + } + ospfd.append("log file /var/log/quagga/ospfd.log").append(","); + + final String tmpCfgFilePath = "/etc/quagga/"; + final String tmpCfgFileName = "ospfd.conf.new." + String.valueOf(System.currentTimeMillis()); + + final QuaggaRule quaggaRule = new QuaggaRule(zebra.toString(), ospfd.toString(), tmpCfgFilePath, tmpCfgFileName, vrIp); + + return generateConfigItems(quaggaRule); + } --- End diff -- This method appears to work with the following concerns: 1. A common zerba/ospfd configuration format (lines of space separated values ending with a ``,`` with child items idented with a two (2) spaces). It also includes conversion of various types to ``String``. 1. Generation of a zebra configuration 1. Generation of an ospfd configuration The mix of these concerns has created repeating groups and a method that is larger than necessary. Please consider decomposing as follows: 1. Create a ``QuaggaConfFileBuilder`` class that encapsulates the configuration file format concern. This class could methods such as ``QuaggaConfFileBuilder withDirective(String... elements)`` that joins the passed ``elements`` with a space and appends a comma; ``QuaggaConfFileBuilder addChildDirective()`` which returns a nested builder to represent the indentation hierarchy; etc. 1. Split the creation of the zebra and ospf configurations into separate private methods or individual small classes. The decision as to which approach would be most effective would depend on how many rules/data type conversions need to be represented. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---