Merge "Added missing columns to flow table db and tests" into topic/schema
[netvirt.git] / plugin / src / main / java / org / opendaylight / ovsdb / plugin / Connection.java
1 /*
2  * Copyright (C) 2013 Red Hat, Inc.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Authors : Madhu Venugopal, Brent Salisbury
9  */
10 package org.opendaylight.ovsdb.plugin;
11
12 import org.opendaylight.controller.sal.core.ConstructionException;
13 import org.opendaylight.controller.sal.core.Node;
14 import org.opendaylight.controller.sal.utils.Status;
15 import org.opendaylight.controller.sal.utils.StatusCode;
16 import org.opendaylight.ovsdb.lib.OvsdbClient;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class Connection {
21     private Node node;
22     private String identifier;
23     private OvsdbClient client;
24
25     public Long getIdCounter() {
26         return idCounter;
27     }
28
29     public void setIdCounter(Long idCounter) {
30         this.idCounter = idCounter;
31     }
32
33     private Long idCounter;
34
35     private static final Logger logger = LoggerFactory.getLogger(Connection.class);
36
37     public Connection(String identifier, OvsdbClient client) {
38
39         super();
40
41         this.identifier = identifier;
42         this.client = client;
43         this.idCounter = 0L;
44         try {
45             node = new Node("OVS", identifier);
46         } catch (ConstructionException e) {
47             logger.error("Error creating OVS node with identifier " + identifier, e);
48         }
49     }
50
51     public String getIdentifier() {
52         return identifier;
53     }
54
55     public void setIdentifier(String identifier) {
56         this.identifier = identifier;
57     }
58
59     public OvsdbClient getClient() {
60         return this.client;
61     }
62
63     public void setClient(OvsdbClient client) {
64         this.client = client;
65     }
66
67     public Node getNode() {
68         return node;
69     }
70
71     public void setNode(Node node) {
72         this.node = node;
73     }
74
75     public Status disconnect() {
76         return new Status(StatusCode.SUCCESS);
77     }
78
79     @Override
80     public int hashCode() {
81         final int prime = 31;
82         int result = 1;
83         result = prime * result + ((identifier == null) ? 0 : identifier.hashCode());
84         return result;
85     }
86
87     @Override
88     public boolean equals(Object obj) {
89         if (this == obj) return true;
90         if (obj == null) return false;
91         if (getClass() != obj.getClass()) return false;
92         Connection other = (Connection) obj;
93         if (identifier == null) {
94             if (other.identifier != null) return false;
95         } else if (!identifier.equals(other.identifier)) return false;
96         return true;
97     }
98 }