コード例 #1
0
bool ThriftConfigApplier::updateDhcpOverrides(Vlan* vlan,
        const cfg::Vlan* config) {
    DhcpV4OverrideMap newDhcpV4OverrideMap;
    for (const auto& pair : config->dhcpRelayOverridesV4) {
        try {
            newDhcpV4OverrideMap[MacAddress(pair.first)] = IPAddressV4(pair.second);
        } catch (const IPAddressFormatException& ex) {
            throw FbossError("Invalid IPv4 address in DHCPv4 relay override map: ",
                             ex.what());
        }
    }

    DhcpV6OverrideMap newDhcpV6OverrideMap;
    for (const auto& pair : config->dhcpRelayOverridesV6) {
        try {
            newDhcpV6OverrideMap[MacAddress(pair.first)] = IPAddressV6(pair.second);
        } catch (const IPAddressFormatException& ex) {
            throw FbossError("Invalid IPv4 address in DHCPv4 relay override map: ",
                             ex.what());
        }
    }

    bool changed = false;
    auto oldDhcpV4OverrideMap = vlan->getDhcpV4RelayOverrides();
    if (oldDhcpV4OverrideMap != newDhcpV4OverrideMap) {
        vlan->setDhcpV4RelayOverrides(newDhcpV4OverrideMap);
        changed = true;
    }
    auto oldDhcpV6OverrideMap = vlan->getDhcpV6RelayOverrides();
    if (oldDhcpV6OverrideMap != newDhcpV6OverrideMap) {
        vlan->setDhcpV6RelayOverrides(newDhcpV6OverrideMap);
        changed = true;
    }
    return changed;
}
コード例 #2
0
ファイル: Vlan.cpp プロジェクト: Gardenya/fboss
Vlan::Vlan(const cfg::Vlan* config, uint32_t mtu, MemberPorts ports)
  : NodeBaseT(VlanID(config->id),
              config->name,
              mtu,
              (config->__isset.dhcpRelayAddressV4 ?
               IPAddressV4(config->dhcpRelayAddressV4) : IPAddressV4()),
              (config->__isset.dhcpRelayAddressV6 ?
               IPAddressV6(config->dhcpRelayAddressV6) : IPAddressV6()),
               std::move(ports)) {

  DhcpV4OverrideMap map4;
  for (const auto& o: config->dhcpRelayOverridesV4) {
    map4[MacAddress(o.first)] = folly::IPAddressV4(o.second);
  }
  setDhcpV4RelayOverrides(map4);

  DhcpV6OverrideMap map6;
  for (const auto& o: config->dhcpRelayOverridesV6) {
    map6[MacAddress(o.first)] = folly::IPAddressV6(o.second);
  }
  setDhcpV6RelayOverrides(map6);
}