Program: 106023
Project: 106023
Buggy source:
protected LinkedHashMap<Network,NicProfile> createRouterNetworks(Account owner,boolean isRedundant,DeploymentPlan plan,Network guestNetwork,Pair<Boolean,PublicIp> publicNetwork) throws ConcurrentOperationException, InsufficientAddressCapacityException {
  boolean setupPublicNetwork=false;
  if (publicNetwork != null) {
    setupPublicNetwork=publicNetwork.first();
  }
  LinkedHashMap<Network,NicProfile> networks=new LinkedHashMap<Network,NicProfile>(3);
  boolean hasGuestNetwork=false;
  if (guestNetwork != null) {
    s_logger.debug("String_Node_Str" + guestNetwork);
    String defaultNetworkStartIp=null, defaultNetworkStartIpv6=null;
    if (!setupPublicNetwork) {
      Nic placeholder=_networkModel.getPlaceholderNicForRouter(guestNetwork,plan.getPodId());
      if (guestNetwork.getCidr() != null) {
        if (placeholder != null && placeholder.getIp4Address() != null) {
          s_logger.debug("String_Node_Str" + placeholder.getIp4Address() + "String_Node_Str"+ guestNetwork);
          defaultNetworkStartIp=placeholder.getIp4Address();
        }
 else {
          String startIp=_networkModel.getStartIpAddress(guestNetwork.getId());
          if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(),startIp).getAllocatedTime() == null) {
            defaultNetworkStartIp=startIp;
          }
 else           if (s_logger.isDebugEnabled()) {
            s_logger.debug("String_Node_Str" + startIp + "String_Node_Str"+ guestNetwork.getId()+ "String_Node_Str");
          }
        }
      }
      if (guestNetwork.getIp6Cidr() != null) {
        if (placeholder != null && placeholder.getIp6Address() != null) {
          s_logger.debug("String_Node_Str" + placeholder.getIp6Address() + "String_Node_Str"+ guestNetwork);
          defaultNetworkStartIpv6=placeholder.getIp6Address();
        }
 else {
          String startIpv6=_networkModel.getStartIpv6Address(guestNetwork.getId());
          if (startIpv6 != null && _ipv6Dao.findByNetworkIdAndIp(guestNetwork.getId(),startIpv6) == null) {
            defaultNetworkStartIpv6=startIpv6;
          }
 else           if (s_logger.isDebugEnabled()) {
            s_logger.debug("String_Node_Str" + startIpv6 + "String_Node_Str"+ guestNetwork.getId()+ "String_Node_Str");
          }
        }
      }
    }
    NicProfile gatewayNic=new NicProfile(defaultNetworkStartIp,defaultNetworkStartIpv6);
    if (setupPublicNetwork) {
      if (isRedundant) {
        gatewayNic.setIp4Address(_ipAddrMgr.acquireGuestIpAddress(guestNetwork,null));
      }
 else {
        gatewayNic.setIp4Address(guestNetwork.getGateway());
      }
      gatewayNic.setBroadcastUri(guestNetwork.getBroadcastUri());
      gatewayNic.setBroadcastType(guestNetwork.getBroadcastDomainType());
      gatewayNic.setIsolationUri(guestNetwork.getBroadcastUri());
      gatewayNic.setMode(guestNetwork.getMode());
      String gatewayCidr=guestNetwork.getCidr();
      gatewayNic.setNetmask(NetUtils.getCidrNetmask(gatewayCidr));
    }
 else {
      gatewayNic.setDefaultNic(true);
    }
    networks.put(guestNetwork,gatewayNic);
    hasGuestNetwork=true;
  }
  s_logger.debug("String_Node_Str");
  List<? extends NetworkOffering> offerings=_networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork);
  NetworkOffering controlOffering=offerings.get(0);
  Network controlConfig=_networkMgr.setupNetwork(_systemAcct,controlOffering,plan,null,null,false).get(0);
  networks.put(controlConfig,null);
  if (setupPublicNetwork) {
    PublicIp sourceNatIp=publicNetwork.second();
    s_logger.debug("String_Node_Str");
    NicProfile defaultNic=new NicProfile();
    defaultNic.setDefaultNic(true);
    defaultNic.setIp4Address(sourceNatIp.getAddress().addr());
    defaultNic.setGateway(sourceNatIp.getGateway());
    defaultNic.setNetmask(sourceNatIp.getNetmask());
    defaultNic.setMacAddress(sourceNatIp.getMacAddress());
    defaultNic.setBroadcastType(BroadcastDomainType.Vlan);
    defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag()));
    defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag()));
    if (hasGuestNetwork) {
      defaultNic.setDeviceId(2);
    }
    NetworkOffering publicOffering=_networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork).get(0);
    List<? extends Network> publicNetworks=_networkMgr.setupNetwork(_systemAcct,publicOffering,plan,null,null,false);
    String publicIp=defaultNic.getIp4Address();
    NicVO peerNic=_nicDao.findByIp4AddressAndNetworkId(publicIp,publicNetworks.get(0).getId());
    if (peerNic != null) {
      s_logger.info("String_Node_Str" + peerNic.getMacAddress());
      defaultNic.setMacAddress(peerNic.getMacAddress());
    }
    networks.put(publicNetworks.get(0),defaultNic);
  }
  return networks;
}

Fixed version (ground truth):
protected LinkedHashMap<Network,NicProfile> createRouterNetworks(Account owner,boolean isRedundant,DeploymentPlan plan,Network guestNetwork,Pair<Boolean,PublicIp> publicNetwork) throws ConcurrentOperationException, InsufficientAddressCapacityException {
  boolean setupPublicNetwork=false;
  if (publicNetwork != null) {
    setupPublicNetwork=publicNetwork.first();
  }
  LinkedHashMap<Network,NicProfile> networks=new LinkedHashMap<Network,NicProfile>(3);
  boolean hasGuestNetwork=false;
  if (guestNetwork != null) {
    s_logger.debug("String_Node_Str" + guestNetwork);
    String defaultNetworkStartIp=null, defaultNetworkStartIpv6=null;
    if (!setupPublicNetwork) {
      Nic placeholder=_networkModel.getPlaceholderNicForRouter(guestNetwork,plan.getPodId());
      if (guestNetwork.getCidr() != null) {
        if (placeholder != null && placeholder.getIp4Address() != null) {
          s_logger.debug("String_Node_Str" + placeholder.getIp4Address() + "String_Node_Str"+ guestNetwork);
          defaultNetworkStartIp=placeholder.getIp4Address();
        }
 else {
          String startIp=_networkModel.getStartIpAddress(guestNetwork.getId());
          if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(),startIp).getAllocatedTime() == null) {
            defaultNetworkStartIp=startIp;
          }
 else           if (s_logger.isDebugEnabled()) {
            s_logger.debug("String_Node_Str" + startIp + "String_Node_Str"+ guestNetwork.getId()+ "String_Node_Str");
          }
        }
      }
      if (guestNetwork.getIp6Cidr() != null) {
        if (placeholder != null && placeholder.getIp6Address() != null) {
          s_logger.debug("String_Node_Str" + placeholder.getIp6Address() + "String_Node_Str"+ guestNetwork);
          defaultNetworkStartIpv6=placeholder.getIp6Address();
        }
 else {
          String startIpv6=_networkModel.getStartIpv6Address(guestNetwork.getId());
          if (startIpv6 != null && _ipv6Dao.findByNetworkIdAndIp(guestNetwork.getId(),startIpv6) == null) {
            defaultNetworkStartIpv6=startIpv6;
          }
 else           if (s_logger.isDebugEnabled()) {
            s_logger.debug("String_Node_Str" + startIpv6 + "String_Node_Str"+ guestNetwork.getId()+ "String_Node_Str");
          }
        }
      }
    }
    NicProfile gatewayNic=new NicProfile(defaultNetworkStartIp,defaultNetworkStartIpv6);
    if (setupPublicNetwork) {
      if (isRedundant) {
        gatewayNic.setIp4Address(_ipAddrMgr.acquireGuestIpAddress(guestNetwork,null));
      }
 else {
        gatewayNic.setIp4Address(guestNetwork.getGateway());
      }
      gatewayNic.setBroadcastUri(guestNetwork.getBroadcastUri());
      gatewayNic.setBroadcastType(guestNetwork.getBroadcastDomainType());
      gatewayNic.setIsolationUri(guestNetwork.getBroadcastUri());
      gatewayNic.setMode(guestNetwork.getMode());
      String gatewayCidr=guestNetwork.getCidr();
      gatewayNic.setNetmask(NetUtils.getCidrNetmask(gatewayCidr));
    }
 else {
      gatewayNic.setDefaultNic(true);
    }
    networks.put(guestNetwork,gatewayNic);
    hasGuestNetwork=true;
  }
  s_logger.debug("String_Node_Str");
  List<? extends NetworkOffering> offerings=_networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork);
  NetworkOffering controlOffering=offerings.get(0);
  Network controlConfig=_networkMgr.setupNetwork(_systemAcct,controlOffering,plan,null,null,false).get(0);
  networks.put(controlConfig,null);
  if (setupPublicNetwork) {
    PublicIp sourceNatIp=publicNetwork.second();
    s_logger.debug("String_Node_Str");
    NicProfile defaultNic=new NicProfile();
    defaultNic.setDefaultNic(true);
    defaultNic.setIp4Address(sourceNatIp.getAddress().addr());
    defaultNic.setGateway(sourceNatIp.getGateway());
    defaultNic.setNetmask(sourceNatIp.getNetmask());
    defaultNic.setMacAddress(sourceNatIp.getMacAddress());
    Network pubNet=_networkDao.findById(sourceNatIp.getNetworkId());
    if (pubNet.getBroadcastDomainType() == BroadcastDomainType.Vxlan) {
      defaultNic.setBroadcastType(BroadcastDomainType.Vxlan);
      defaultNic.setBroadcastUri(BroadcastDomainType.Vxlan.toUri(sourceNatIp.getVlanTag()));
      defaultNic.setIsolationUri(BroadcastDomainType.Vxlan.toUri(sourceNatIp.getVlanTag()));
    }
 else {
      defaultNic.setBroadcastType(BroadcastDomainType.Vlan);
      defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag()));
      defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag()));
    }
    if (hasGuestNetwork) {
      defaultNic.setDeviceId(2);
    }
    NetworkOffering publicOffering=_networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork).get(0);
    List<? extends Network> publicNetworks=_networkMgr.setupNetwork(_systemAcct,publicOffering,plan,null,null,false);
    String publicIp=defaultNic.getIp4Address();
    NicVO peerNic=_nicDao.findByIp4AddressAndNetworkId(publicIp,publicNetworks.get(0).getId());
    if (peerNic != null) {
      s_logger.info("String_Node_Str" + peerNic.getMacAddress());
      defaultNic.setMacAddress(peerNic.getMacAddress());
    }
    networks.put(publicNetworks.get(0),defaultNic);
  }
  return networks;
}