use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron in project netvirt by opendaylight.
the class NeutronUtils method writePortStatus.
private static boolean writePortStatus(String uuid, String portStatus, DataBroker dataBroker, boolean create) {
Uuid uuidObj = new Uuid(uuid);
PortBuilder portBuilder = new PortBuilder();
portBuilder.setUuid(uuidObj);
portBuilder.setStatus(portStatus);
InstanceIdentifier iid = InstanceIdentifier.create(Neutron.class).child(Ports.class).child(Port.class, new PortKey(uuidObj));
SingleTransactionDataBroker tx = new SingleTransactionDataBroker(dataBroker);
try {
if (create) {
tx.syncWrite(LogicalDatastoreType.OPERATIONAL, iid, portBuilder.build());
} else {
tx.syncUpdate(LogicalDatastoreType.OPERATIONAL, iid, portBuilder.build());
}
} catch (TransactionCommitFailedException e) {
LOG.error("writePortStatus: failed neutron port status write. isCreate: {}", create, e);
return false;
}
return true;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron in project netvirt by opendaylight.
the class NeutronUtils method deletePortStatus.
/**
* Delete a Neutron Port status entry from the operational data store.
* @param uuid The uuid of the Neutron port
* @param dataBroker DataBroker instance
* @return true if transaction submitted successfully
*/
public static boolean deletePortStatus(String uuid, DataBroker dataBroker) {
Uuid uuidObj = new Uuid(uuid);
InstanceIdentifier iid = InstanceIdentifier.create(Neutron.class).child(Ports.class).child(Port.class, new PortKey(uuidObj));
SingleTransactionDataBroker tx = new SingleTransactionDataBroker(dataBroker);
try {
tx.syncDelete(LogicalDatastoreType.OPERATIONAL, iid);
} catch (TransactionCommitFailedException e) {
LOG.error("deletePortStatus: failed neutron port status delete", e);
return false;
}
return true;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron in project netvirt by opendaylight.
the class DhcpPktHandler method onPacketReceived.
// TODO: Handle this in a separate thread
@Override
public void onPacketReceived(PacketReceived packet) {
if (!config.isControllerDhcpEnabled()) {
return;
}
Class<? extends PacketInReason> pktInReason = packet.getPacketInReason();
short tableId = packet.getTableId().getValue();
if ((tableId == NwConstants.DHCP_TABLE || tableId == NwConstants.DHCP_TABLE_EXTERNAL_TUNNEL) && isPktInReasonSendtoCtrl(pktInReason)) {
byte[] inPayload = packet.getPayload();
Ethernet ethPkt = new Ethernet();
try {
ethPkt.deserialize(inPayload, 0, inPayload.length * NetUtils.NUM_BITS_IN_A_BYTE);
} catch (PacketException e) {
LOG.warn("Failed to decode DHCP Packet.", e);
LOG.trace("Received packet {}", packet);
return;
}
DHCP pktIn;
pktIn = getDhcpPktIn(ethPkt);
if (pktIn != null) {
LOG.trace("DHCPPkt received: {}", pktIn);
LOG.trace("Received Packet: {}", packet);
BigInteger metadata = packet.getMatch().getMetadata().getMetadata();
long portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
String macAddress = DHCPUtils.byteArrayToString(ethPkt.getSourceMACAddress());
BigInteger tunnelId = packet.getMatch().getTunnel() == null ? null : packet.getMatch().getTunnel().getTunnelId();
String interfaceName = getInterfaceNameFromTag(portTag);
InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfoFromOperationalDataStore(interfaceName);
if (interfaceInfo == null) {
LOG.error("Failed to get interface info for interface name {}", interfaceName);
return;
}
Port port;
if (tunnelId != null) {
port = dhcpExternalTunnelManager.readVniMacToPortCache(tunnelId, macAddress);
} else {
port = getNeutronPort(interfaceName);
}
Subnet subnet = getNeutronSubnet(port);
String serverMacAddress = interfaceInfo.getMacAddress();
String serverIp = null;
if (subnet != null) {
java.util.Optional<SubnetToDhcpPort> dhcpPortData = DhcpServiceUtils.getSubnetDhcpPortData(broker, subnet.getUuid().getValue());
/* If enable_dhcp_service flag was enabled and an ODL network DHCP Port data was made available use
* the ports Fixed IP as server IP for DHCP communication.
*/
if (dhcpPortData.isPresent()) {
serverIp = dhcpPortData.get().getPortFixedip();
serverMacAddress = dhcpPortData.get().getPortMacaddress();
} else {
// DHCP Neutron Port not found for this network
LOG.error("Neutron DHCP port is not available for the Subnet {} and port {}.", subnet.getUuid(), port.getUuid());
return;
}
}
DHCP replyPkt = handleDhcpPacket(pktIn, interfaceName, macAddress, port, subnet, serverIp);
if (replyPkt == null) {
LOG.warn("Unable to construct reply packet for interface name {}", interfaceName);
return;
}
byte[] pktOut = getDhcpPacketOut(replyPkt, ethPkt, serverMacAddress);
sendPacketOut(pktOut, interfaceInfo.getDpId(), interfaceName, tunnelId);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron in project netvirt by opendaylight.
the class DhcpSubnetListener method update.
@Override
protected void update(InstanceIdentifier<Subnet> identifier, Subnet original, Subnet update) {
LOG.trace("DhcpSubnetListener Update : Original dhcpstatus: {}, Updated dhcpstatus {}", original.isEnableDhcp(), update.isEnableDhcp());
if (!Objects.equals(original.isEnableDhcp(), update.isEnableDhcp())) {
// write api to get port list
SubnetmapBuilder subnetmapBuilder = getSubnetMapBuilder(dataBroker, update.getUuid());
List<Uuid> portList = subnetmapBuilder.getPortList();
List<Uuid> directPortList = subnetmapBuilder.getDirectPortList();
if (update.isEnableDhcp()) {
if (null != portList) {
// Install Entries for neutron ports
installNeutronPortEntries(portList);
}
if (null != directPortList) {
// install Entries for direct ports
installDirectPortEntries(directPortList);
}
} else {
if (null != portList) {
// UnInstall Entries for neutron ports
uninstallNeutronPortEntries(portList);
}
if (null != directPortList) {
// Uninstall Entries for direct ports
uninstallDirectPortEntries(directPortList);
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron in project netvirt by opendaylight.
the class DhcpUCastMacListener method remove.
@Override
protected void remove(InstanceIdentifier<LocalUcastMacs> identifier, LocalUcastMacs del) {
// Flow removal for table 18 is handled in Neutron Port delete.
// remove the new CR-DHCP
NodeId torNodeId = identifier.firstKeyOf(Node.class).getNodeId();
LogicalSwitches logicalSwitch = getLogicalSwitches(del);
if (null == logicalSwitch) {
LOG.error("DhcpUCastMacListener remove :Logical Switch ref doesn't have data");
return;
}
String elanInstanceName = logicalSwitch.getHwvtepNodeName().getValue();
L2GatewayDevice device = ElanL2GwCacheUtils.getL2GatewayDeviceFromCache(elanInstanceName, torNodeId.getValue());
if (device == null) {
LOG.error("Logical Switch Device with name {} is not present in L2GWCONN cache", elanInstanceName);
return;
}
IpAddress tunnelIp = device.getTunnelIp();
Pair<IpAddress, String> tunnelIpElanName = new ImmutablePair<>(tunnelIp, elanInstanceName);
dhcpExternalTunnelManager.removeFromAvailableCache(tunnelIpElanName);
}
Aggregations