cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jburwell <...@git.apache.org>
Subject [GitHub] cloudstack pull request: OSPF: adding dynamically routing capabili...
Date Tue, 10 May 2016 22:10:48 GMT
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<ConfigItem> 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.
---

Mime
View raw message